コード例 #1
0
        private void btnEnumerate_Click(object sender, EventArgs e)
        {
            UInt32    devices_count;
            DL_STATUS status;
            string    status_msg;
            HND_AIS   hnd_device;
            UInt32    Device_Type, Device_ID, Device_FW_VER, Device_CommSpeed,
                      Device_isOpened, Device_Status, System_Status;
            string Device_Serial, Device_FTDI_Serial;

            // Shuld be a warning before close all opened devices
            gridView.Rows.Clear();
            try
            {
                devices_count = ais_readers.AIS_List_UpdateAndGetCount();
                Helper.AppendText(tbLog, "Listed devices succesfully enumerated. ", Color.Green);
                Helper.AppendText(tbLog, "Number of attached devices is: ", Color.Navy);
                Helper.AppendText(tbLog, "" + devices_count + "\n", Color.Black);
                Helper.SetStatusOk(statusLabel);

                if (isAnyDeviceAttached = (devices_count > 0))
                {
                    for (int i = 0; i < devices_count; i++)
                    {
                        try
                        {
                            status = ais_readers.AIS_List_GetInformation(
                                out hnd_device,         // assigned Handle
                                out Device_Serial,      // device serial number
                                out Device_Type,        // device type
                                out Device_ID,          // device identification number (master)
                                out Device_FW_VER,      // version of firmware
                                out Device_CommSpeed,   // communication speed
                                out Device_FTDI_Serial, // FTDI COM port identification
                                out Device_isOpened,    // is Device opened
                                out Device_Status,      // actual device status
                                out System_Status       // actual system status
                                );
                            if (status != DL_STATUS.DL_OK)
                            {
                                status_msg = ais_readers.status2str(status);
                                throw new Exception("AIS status: " + status_msg);
                            }
                            else
                            {
                                string[] new_row = new string[] { (i + 1).ToString(), hnd_device.ToString(), Device_Serial,
                                                                  Device_Type.ToString(), Device_ID.ToString(), Device_FW_VER.ToString(),
                                                                  Device_CommSpeed.ToString(), Device_FTDI_Serial, Device_isOpened.ToString(),
                                                                  Device_Status.ToString(), System_Status.ToString() };
                                gridView.Rows.Add(new_row);
                            }
                        }
                        catch (Exception exception)
                        {
                            Helper.AppendText(tbLog, "Warning: ", Color.Purple);
                            Helper.AppendText(tbLog, exception.Message + "\n", Color.Purple);
                            Helper.SetStatusWarning(statusLabel);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Helper.AppendText(tbLog, exception.Message + "\n", Color.Red);
                Helper.SetStatusErr(statusLabel);
            }
        }