Пример #1
0
        public override COMMUNICATERESULT SetData(CommandClass SetInfo)
        {
            int BytestoRec = 8;

            byte[]            RecBytes;
            byte[]            SendCommand;
            COMMUNICATERESULT ret;

            SendCommand = SetInfo.Command;
            if (!USBWrapper.USBConnectState())
            {
                if (USBWrapper.connect() == COMMUNICATERESULT.OK)
                {
                    ret = USBWrapper.SendAndReceive(SendCommand, BytestoRec, out RecBytes);
                }
                else
                {
                    return(COMMUNICATERESULT.PortOpenFail);
                }
            }
            else
            {
                ret = USBWrapper.SendAndReceive(SendCommand, BytestoRec, out RecBytes);
            }
            if (ret == COMMUNICATERESULT.OK)
            {
                ret = CheckData(RecBytes, SendCommand);
            }

            return(ret);
        }
Пример #2
0
 private void OpenDevice()
 {
         #if MONO
     usb_port        = new USBWrapper_Posix();
     usb_report_size = 64;
         #else
     usb_port        = new USBWrapper_Win32();
     usb_report_size = 65;
         #endif
     while (usb_fs == null)
     {
         usb_fs = usb_port.GetUSBHandle(usb_devicefile, usb_report_size);
         if (usb_fs == null)
         {
             if (this.verbose_mode > 0)
             {
                 System.Console.WriteLine("No device");
             }
             System.Threading.Thread.Sleep(5000);
         }
         else
         {
             if (this.verbose_mode > 0)
             {
                 System.Console.WriteLine("USB device found");
             }
         }
     }
 }
Пример #3
0
 public override bool Connect()
 {
     if (USBWrapper.connect() == COMMUNICATERESULT.OK)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #4
0
        public override COMMUNICATERESULT GetData(DeviceBll Device, ref List <byte> AnalogDate, ref List <byte> DigitalData, ref List <string> CharacterData)
        {
            COMMUNICATERESULT ret = new COMMUNICATERESULT();

            ret = COMMUNICATERESULT.OK;
            byte[] SendCommand = null;
            byte[] RecByte     = null;
            byte[] RecData     = null;
            int    BytesToRec  = 0;

            foreach (CommandClass AnalogCommand in Device.Device.AnalogCommandList)
            {
                SendCommand = AnalogCommand.Command;
                BytesToRec  = AnalogCommand.RecLen;
                ret         = USBWrapper.SendAndReceive(SendCommand, BytesToRec, out RecByte);
                if (ret != COMMUNICATERESULT.OK)
                {
                    return(ret);
                }
                ret = CheckData(RecByte, SendCommand);
                if (ret != COMMUNICATERESULT.OK)
                {
                    return(ret);
                }
                RecData = GetRecDataFromRecByte(RecByte);
                AnalogDate.AddRange(RecData);
            }
            foreach (CommandClass DigitalCommand in Device.Device.DigitalCommandList)
            {
                SendCommand = DigitalCommand.Command;
                BytesToRec  = DigitalCommand.RecLen;
                ret         = USBWrapper.SendAndReceive(SendCommand, BytesToRec, out RecByte);
                if (ret != COMMUNICATERESULT.OK)
                {
                    return(ret);
                }
                ret = CheckData(RecByte, SendCommand);
                if (ret != COMMUNICATERESULT.OK)
                {
                    return(ret);
                }
                RecData = GetRecDataFromRecByte(RecByte);
                DigitalData.AddRange(RecData);
            }
            return(COMMUNICATERESULT.OK);
        }
Пример #5
0
        private void GetHandle()
        {
            usb_fs          = null;
            usb_report_size = 32;

            /** prebuild ack and nack messages */
            nack    = new byte[usb_report_size];
            ack     = new byte[usb_report_size];
            nack[0] = 0x2;
            nack[1] = 0x1;
            nack[2] = 0x15;
            ack[0]  = 0x2;
            ack[1]  = 0x1;
            ack[2]  = 0x6;
            for (int i = 3; i < usb_report_size; i++)
            {
                nack[i] = 0;
                ack[i]  = 0;
            }

            usb_port = new USBWrapper_HidSharp();
            while (usb_fs == null)
            {
                usb_fs = usb_port.GetUSBHandle(usb_devicefile, usb_report_size);
                if (usb_fs == null)
                {
                    if (this.verbose_mode > 0)
                    {
                        System.Console.WriteLine("No device");
                    }
                    System.Threading.Thread.Sleep(5000);
                }
                else
                {
                    if (this.verbose_mode > 0)
                    {
                        System.Console.WriteLine("USB device found");
                    }
                }
            }
            //AsyncRead();
        }
Пример #6
0
 public override bool ConnectState()
 {
     return(USBWrapper.USBConnectState());
 }