public Happy_Hounds() { InitializeComponent(); //Initialise Variables int MaxLength = 255; int ListLength = 0; int DeviceListLength; SByte[] NameList = new SByte[1000]; SByte[] DeviceList = new SByte[MaxLength]; //Grab USB Device Names DeviceListLength = GIS_LF_API.TSLF_GetUSBDeviceNames(DeviceList, MaxLength) - 1; CopyArrayTo(DeviceList, 0, NameList, ListLength, DeviceListLength); ListLength += DeviceListLength; ListLength++; if (ListLength > 1) { string DeviceName; // Use first Device in List DeviceName = MakeStringFromArray(NameList, 0); PortHandle = GIS_LF_API.TSLF_Open(MakeArrayFromString(DeviceName), 19200, 0, 500); if (GIS_LF_API.TSLF_IsProgrammer(PortHandle) != 1) { MessageBox.Show("Device is not a Programmer"); } } else { PortHandle = 0; } if (PortHandle <= 0) { MessageBox.Show("Device could not be opened"); } }
public Form1() { InitializeComponent(); btnStart.Enabled = false; btnStop.Enabled = false; m_oWorker = new BackgroundWorker(); // Create a background worker thread that ReportsProgress & // SupportsCancellation // Hook up the appropriate events. m_oWorker.DoWork += new DoWorkEventHandler(m_oWorker_DoWork); m_oWorker.ProgressChanged += new ProgressChangedEventHandler (m_oWorker_ProgressChanged); m_oWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler (m_oWorker_RunWorkerCompleted); m_oWorker.WorkerReportsProgress = true; m_oWorker.WorkerSupportsCancellation = true; int MaxLen = 255; int ListLen = 0; int DevListLen; SByte[] NamenListe = new SByte[1000]; SByte[] DevList = new SByte[MaxLen]; DevListLen = GIS_LF_API.TSLF_GetUSBDeviceNames(DevList, MaxLen) - 1; CopyArrayTo(DevList, 0, NamenListe, ListLen, DevListLen); ListLen += DevListLen; DevListLen = GIS_LF_API.TSLF_GetLanDeviceNames(DevList, MaxLen) - 1; CopyArrayTo(DevList, 0, NamenListe, ListLen, DevListLen); ListLen += DevListLen; DevListLen = GIS_LF_API.TSLF_GetCOMDeviceNames(DevList, MaxLen) - 1; CopyArrayTo(DevList, 0, NamenListe, ListLen, DevListLen); ListLen += DevListLen; ListLen++; if (ListLen > 1) { string DeviceName; // Use first Device in List DeviceName = MakeStringFromArray(NamenListe, 0); PortHandle = GIS_LF_API.TSLF_Open(MakeArrayFromString(DeviceName), 19200, 0, 500); if (GIS_LF_API.TSLF_IsProgrammer(PortHandle) != 1) { MessageBox.Show("Device is no Programmer"); GIS_LF_API.TSLF_Close(PortHandle); PortHandle = 0; } else { // Get device version from device, to cehck if read device is connected. // The first 3 digits of the string give the device number // valid device number is 039 for TS-W34AC, 244 for TS-RW38AC sbyte[] Version = new sbyte[4]; sbyte[] InternalDeviceName = new sbyte[32]; int nReturn = GIS_LF_API.TSLF_GetDeviceVersion(PortHandle, Version, 4, InternalDeviceName, 32); if (nReturn == -1) { int Error = GIS_LF_API.TSLF_GetLastError(PortHandle); MessageBox.Show("DeviceVersion can not be read"); GIS_LF_API.TSLF_Close(PortHandle); PortHandle = 0; } else { if (IsAnimalHDXProgrammer(Version)) { // Device is valid } else { // Invalid device, will be closed MessageBox.Show("Connected device is no Animal programmer!"); GIS_LF_API.TSLF_Close(PortHandle); PortHandle = 0; } } } } else { PortHandle = 0; } if (PortHandle <= 0) { MessageBox.Show("Device could not be opened"); } else { // Turn off Antenna GIS_LF_API.TSLF_SetRF(PortHandle, 0); } }