コード例 #1
0
        private void checkbtn_Click(object sender, EventArgs e)
        {
            port          = new ASCOM.Utilities.Serial();
            port.PortName = comboBoxComPort.SelectedItem.ToString();
            port.Speed    = (SerialSpeed)9600;
            port.StopBits = SerialStopBits.One;
            port.DataBits = 8;
            port.Parity   = SerialParity.None;

            try
            {
                port.Connected = true;
                byte[] request = new byte[6] {
                    0xA5, 0x3, 0x2, 0x0, 0x0, 0xAA
                };
                port.TransmitBinary(request);
                port.ReceiveTimeoutMs = 100;
                byte[] receive = port.ReceiveCountedBinary(6);
                txtConnect.AppendText("Connected");
                cmdOK.Enabled  = true;
                port.Connected = false;
            }
            catch
            {
                MessageBox.Show("No SBIG CFW-10 filter wheel found on current COM port!", "ASCOM Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        static uint getSetPos(ASCOM.Utilities.Serial sp)
        {
            sp.TransmitBinary(LinShengStepMotor.cmd_query_setpos);
            byte[] resp = sp.ReceiveCountedBinary(7);
            uint   pos  = LinShengStepMotor.extrace_query_response_value_0_3(resp);

            return(pos);
        }
コード例 #3
0
        //Basic write function for virtual interface. Override based on attached hardware type or not. 
        public int Write( byte proxyAddress, byte targetAddress, byte[] data )
        {
            byte[] outData;
            byte[] output;
            int buffLength = 0;
            int i=0, j=0, writtenCount=0;

            //grab  mutex or wait
            lock(localLock)
            {
                //setup output buffers
                if( proxyAddress == null )
                {
                    buffLength = data.Length+1;
                    outData = new byte[ buffLength];
                }
                else
                {
                    buffLength = data.Length+2;
                    outData = new byte[ buffLength ];
                    outData[i++] = proxyAddress;
                }
                outData[i++] = (byte)( ( targetAddress & 0x7F) | (byte)I2C_WR );
                for ( j=0; j<= buffLength; j++) 
                    outData[i+j] = data[i-1];
                try
                {
                    commPort.TransmitBinary(outData);
                    commPort.ReceiveTimeoutMs = 500;
                    output = commPort.ReceiveCountedBinary( 1 ); //expect status byte
                    writtenCount = output.Length;
                }
                catch (ASCOM.NotConnectedException ex1)
                {
                    commPort.LogMessage("ERROR", "commport not connected error in DeviceComms.I2CSerialComms.i2CWrite");
                }
                catch (ASCOM.Utilities.Exceptions.SerialPortInUseException ex2)
                { 
                    commPort.LogMessage("ERROR", "commport already in use error in DeviceComms.I2CSerialComms.i2CWrite");
                }                
            }
            
        return writtenCount;
        }
コード例 #4
0
 static SpeedInfo getCurrentSpeed(ASCOM.Utilities.Serial sp)
 {
     sp.TransmitBinary(LinShengStepMotor.cmd_query_cur_speed);
     byte[] resp = sp.ReceiveCountedBinary(6);
     return(LinShengStepMotor.extrace_query_response_speed(resp));
 }