/// <summary> /// Initialize the reader. /// </summary> private void InitAudio() { Symbol.Audio.Device MyAudioDevice = (Symbol.Audio.Device)SelectDevice.Select( Symbol.Audio.Controller.Title, Symbol.Audio.Device.AvailableDevices); if (MyAudioDevice == null) { throw new SymbolRFGunException("Unable to initialize audio device."); } //check the device type switch (MyAudioDevice.AudioType) { //if standard device case Symbol.Audio.AudioType.StandardAudio: MyAudioController = new Symbol.Audio.StandardAudio(MyAudioDevice); break; //if simulated device case Symbol.Audio.AudioType.SimulatedAudio: MyAudioController = new Symbol.Audio.SimulatedAudio(MyAudioDevice); break; default: throw new SymbolRFGunException("Unknown Device Type"); } }
/// <summary> /// When the form is closing (exiting) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HideIt_FormClosing(object sender, FormClosingEventArgs e) { if (this._processor != null) { try { this._processor.Dispose(); this._processor = null; } catch (Exception) { } } if (this._liveProcessor != null) { this._liveProcessor.Dispose(); this._liveProcessor = null; } if (this._receiver != null) { try { this._receiver.Dispose(); } catch (Exception) { } } if (this.pic_coverPreview.Image != null) { ///Dispose off the image displayed in preview box this.pic_coverPreview.Image.Dispose(); } if (this.pic_stegoPreview.Image != null) { ///Dipose off the stego object image displayed in preview box this.pic_stegoPreview.Image.Dispose(); } if (this._selectDevice != null) { if (this._selectDevice.CaptureDevice != null) { try { this._selectDevice.CaptureDevice.Dispose(); } catch (Exception) { } this._selectDevice.CaptureDevice = null; } this._selectDevice = null; } }
public HideItUI() { InitializeComponent(); ///Register DoWork and RunWorkerCompleted this.backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork); this.backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted); ///Set the maximam length of key that is acceptable this.txt_key.MaxLength = Stego.Message.MAX_KEY_LEN; StegoProcessorBase.SetupProgressBar = new SetupProgressBarCallback(this.SetupProgressBar); StegoProcessorBase.UpdateProgressBar = new UpdateProgressBarCallback(this.UpdateProgressBar); this._acceptFile = new AcceptFileCallback(this.AcceptFile); this._selectDevice = new SelectDevice(); }
private void button1_Click(object sender, EventArgs e) { try { if (MapTabControl.TabPages.Count > 0) { SubFormas.SelectDevice p = new SelectDevice(MapTabControl.SelectedTab); p.Show(); } else { MetroMessageBox.Show(TNetworkAdministrator.Form1.ActiveForm, "Primeiro Adicione uma localização", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { throw; } }
public bool Connect() { // Find all of the installed J2534 passthru devices List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices(); J2534Device j2534Device; var sd = new SelectDevice(); if (sd.ShowDialog() == DialogResult.OK) { j2534Device = sd.Device; } else { return(false); } // We will always choose the first J2534 device in the list, if there are multiple devices // installed, you should do something more intelligent. m_j2534Interface.LoadLibrary(j2534Device); // Attempt to open a communication link with the pass thru device int deviceId = 0; m_status = m_j2534Interface.PassThruOpen(IntPtr.Zero, ref deviceId); if (m_status != J2534Err.STATUS_NOERROR) { return(false); } if (ConnectSWCan(deviceId, ref m_swChannelId) && ConnectDWCan(deviceId, ref m_dwChannelId)) { m_isConnected = true; SetNullFilters(m_swChannelId, m_dwChannelId); return(true); } return(false); }
private void ScanToLocationViewLoad(object sender, EventArgs e) { uxLabelOperatorCode.Text = OperatorCode; try { _myRFGun = new SymbolRFGun.SymbolRFGun(); _myRFGun.RFScan += MyRFGunRFScan; } catch (SymbolRFGunException ex) { MessageBox.Show(ex.Message); Close(); } try { //Select Device from device list Debug.Assert(Device.AvailableDevices != null, "Device.AvailableDevices != null"); var myDevice = (Device)SelectDevice.Select( Controller.Title, Device.AvailableDevices); if (myDevice == null) { MessageBox.Show("No Device Selected", "SelectDevice"); //close the form Close(); return; } //check the device type switch (myDevice.AudioType) { //if standard device case AudioType.StandardAudio: _myAudioController = new StandardAudio(myDevice); break; //if simulated device case AudioType.SimulatedAudio: _myAudioController = new SimulatedAudio(myDevice); break; default: throw new InvalidDataTypeException("Unknown Device Type"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } try { using (var racksDT = new RackListTableAdapter().GetRackList(Plant)) { RackSelection.DataSource = racksDT; RackSelection.DisplayMember = "Rack"; RackSelection.Text = BeginPhysicalRack; } using (var shelvesDT = new ShelfListTableAdapter().GetShelfList(Plant)) { ShelfSelection.DataSource = shelvesDT; ShelfSelection.DisplayMember = "Shelf"; ShelfSelection.Text = BeginPhysicalShelf; } using (var positionsDT = new PositionListTableAdapter().GetPositionList(Plant)) { PositionSelection.DataSource = positionsDT; PositionSelection.DisplayMember = "Position"; PositionSelection.Text = BeginPhysicalPosition; } } catch (SqlException ex) { foreach (SqlError sqlErr in ex.Errors) { MessageBox.Show(sqlErr.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } RefreshProgress(); }
/* * * Example 2: * Use the J2534 protocol to send and receive a message (w/o error checking) * */ private void SendReceiveNoErrorChecking(object sender, EventArgs e) { J2534Extended passThru = new J2534Extended(); // Find all of the installed J2534 passthru devices List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices(); J2534Device j2534Device; var sd = new SelectDevice(); if (sd.ShowDialog() == DialogResult.OK) { j2534Device = sd.Device; } else { return; } // We will always choose the first J2534 device in the list, if there are multiple devices // installed, you should do something more intelligent. passThru.LoadLibrary(j2534Device); // Attempt to open a communication link with the pass thru device int deviceId = 0; passThru.PassThruOpen(IntPtr.Zero, ref deviceId); // Open a new channel configured for ISO15765 (CAN) int channelId = 0; passThru.PassThruConnect(deviceId, ProtocolID.ISO15765, ConnectFlag.NONE, BaudRate.ISO15765, ref channelId); // Set up a message filter to watch for response messages int filterId = 0; PassThruMsg maskMsg = new PassThruMsg( ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0xff, 0xff, 0xff, 0xff }); PassThruMsg patternMsg = new PassThruMsg( ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0x00, 0x00, 0x07, 0xE8 }); PassThruMsg flowControlMsg = new PassThruMsg( ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0x00, 0x00, 0x07, 0xE0 }); IntPtr maskMsgPtr = maskMsg.ToIntPtr(); IntPtr patternMsgPtr = patternMsg.ToIntPtr(); IntPtr flowControlMsgPtr = flowControlMsg.ToIntPtr(); passThru.PassThruStartMsgFilter(channelId, FilterType.FLOW_CONTROL_FILTER, maskMsgPtr, patternMsgPtr, flowControlMsgPtr, ref filterId); // Clear out the response buffer so we know we're getting the freshest possible data passThru.ClearRxBuffer(channelId); // Finally we can send the message! PassThruMsg txMsg = new PassThruMsg( ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0x00, 0x00, 0x07, 0xdf, 0x01, 0x00 }); var txMsgPtr = txMsg.ToIntPtr(); int numMsgs = 1; passThru.PassThruWriteMsgs(channelId, txMsgPtr, ref numMsgs, 50); // Read messages in a loop until we either timeout or we receive data numMsgs = 1; IntPtr rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)) * numMsgs); J2534Err status = J2534Err.STATUS_NOERROR; while (J2534Err.STATUS_NOERROR == status) { status = passThru.PassThruReadMsgs(channelId, rxMsgs, ref numMsgs, 200); } // If we received data, we want to extract the data of interest. I'm removing the reflection of the transmitted message. if ((J2534Err.ERR_BUFFER_EMPTY == status || J2534Err.ERR_TIMEOUT == status) && numMsgs > 0) { foreach (PassThruMsg msg in rxMsgs.AsList <PassThruMsg>(numMsgs)) { // // // Now do something with the data! // // } } // Disconnect this channel passThru.PassThruDisconnect(channelId); // When we are done with the device, we can free the library. passThru.FreeLibrary(); }
public void LoadLibs() { busy = true; IntPtr _dllHandle; IntPtr _fptr; string _dll1 = "DLL\\eSPAEAWBCtrl.dll"; string _dll2 = "DLL\\eSPDI.dll"; string Function_Name = ""; SetDllDirectory("DLL\\"); _dllHandle = LoadLibrary(_dll1); if (_dllHandle == IntPtr.Zero) { errors.Add("Error loading DLL: " + _dll2 + "\n" + Marshal.GetLastWin32Error().ToString()); // Error Code while loading DLL } Function_Name = "_eSPAEAWB_EnumDevice@4"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _enumDevice = (enumDevice)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(enumDevice)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_GetDevicename@12"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _GetDeviceName = (GetDeviceName)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetDeviceName)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_SelectDevice@4"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _SelectDevice = (SelectDevice)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SelectDevice)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_SetSensorType@4"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _SetSensorType = (SetSensorType)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SetSensorType)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_SWUnlock@4"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _SWUnlock = (SWUnlock)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SWUnlock)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_SWLock@4"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _SWLock = (SWLock)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SWLock)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_DisableAE@0"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _DisableAE = (DisableAE)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(DisableAE)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_DisableAWB@0"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _DisableAWB = (DisableAWB)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(DisableAWB)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_GetGPIOValue@8"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _GetGPIOValue = (GetGPIOValue)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetGPIOValue)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_SetGPIOValue@8"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _SetGPIOValue = (SetGPIOValue)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SetGPIOValue)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_GetAccMeterValue@12"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _GetAccMeterValue = (GetAccMeterValue)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetAccMeterValue)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "_eSPAEAWB_ReadFlash@8"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _ReadFlash = (ReadFlash)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(ReadFlash)); } else { errors.Add("Error loading DLL function: " + Function_Name); } // Switching to functions from second (ETron) DLL file now _dllHandle = LoadLibrary(_dll2); if (_dllHandle == IntPtr.Zero) { errors.Add("Error loading DLL: " + _dll2 + "\n" + Marshal.GetLastWin32Error().ToString()); // Error Code while loading DLL } Function_Name = "EtronDI_Init"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _SPDI_Init = (SPDI_Init)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(SPDI_Init)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "EtronDI_GetDeviceNumber"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _GetDeviceNumber = (GetDeviceNumber)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(GetDeviceNumber)); } else { errors.Add("Error loading DLL function: " + Function_Name); } Function_Name = "EtronDI_FindDevice"; _fptr = GetProcAddress(_dllHandle, Function_Name); if (_fptr != IntPtr.Zero) { _FindDevice = (FindDevice)Marshal.GetDelegateForFunctionPointer(_fptr, typeof(FindDevice)); } else { errors.Add("Error loading DLL function: " + Function_Name); } if (errors.Count == 0) { messages.Add("Loaded Libraries!"); } busy = false; }
bool LoadJ2534() { if (_passThru == null) { _passThru = new J2534Extended(); } if (_passThru.IsLoaded) { return(true); } J2534Device j2534Device; // Find all of the installed J2534 passthru devices List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices(); if (availableJ2534Devices.Count == 0) { MessageBox.Show("Could not find any installed J2534 devices in the Windows registry, have you installed the device drivers for your cable?"); _passThru.FreeLibrary(); return(false); } if (autoDetectCheckBox.Checked) { foreach (var lib in availableJ2534Devices) { if (Path.GetFileName(lib.FunctionLibrary).Contains("J2534DotNet.Logger.dll")) { continue; } try { j2534Device = new J2534Device(); if (!_passThru.LoadLibrary(lib)) { j2534Device = null; continue; } _comm = new UDSFord(_passThru); _comm.Connect(); //if we get this far then we have successfully connected _comm.Disconnect(); return(true); } catch { j2534Device = null; continue; } } _passThru.FreeLibrary(); return(false); } if (checkBoxLogJ2534.Checked) { j2534Device = new J2534Device(); j2534Device.FunctionLibrary = System.IO.Directory.GetCurrentDirectory() + "\\" + "J2534DotNet.Logger.dll"; Thread.Sleep(10); var loaded = _passThru.LoadLibrary(j2534Device); if (!loaded) { _passThru.FreeLibrary(); } return(loaded); } //If there is only one DLL to choose from then load it if (availableJ2534Devices.Count == 1) { return(_passThru.LoadLibrary(availableJ2534Devices[0])); } else { var sd = new SelectDevice(); if (sd.ShowDialog() == DialogResult.OK) { j2534Device = sd.Device; var loaded = _passThru.LoadLibrary(j2534Device); if (!loaded) { _passThru.FreeLibrary(); } return(loaded); } } return(false); }