Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #3
0
        public static void moveAndWaitStep(bool add, uint nstep, ASCOM.Utilities.Serial port)
        {
            byte[] cmd = add ? LinShengStepMotor.cmd_acc_add_relative_position(nstep) :
                         LinShengStepMotor.cmd_acc_sub_relative_position(nstep);

            port.TransmitBinary(cmd);

            waitForFinish(port);
        }
Exemple #4
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;
        }
        /// <summary>
        /// Contains all filter positions and sends the respective hex bytes to the Port
        /// </summary>

        public void MoveFilter(int pos)
        {
            byte[] position = new byte[6];

            if (pos == 1)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x1, 0x0, 0xBA };
            }

            else if (pos == 2)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x2, 0x0, 0xBB };
            }

            else if (pos == 3)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x3, 0x0, 0xBC };
            }

            else if (pos == 4)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x4, 0x0, 0xBD };
            }

            else if (pos == 5)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x5, 0x0, 0xBE };
            }

            else if (pos == 6)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x6, 0x0, 0xBF };
            }

            else if (pos == 7)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x7, 0x0, 0xC0 };
            }

            else if (pos == 8)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x8, 0x0, 0xC1 };
            }

            else if (pos == 9)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0x9, 0x0, 0xC2 };
            }

            else if (pos == 10)
            {
                position = new byte[] { 0xA5, 0x3, 0x11, 0xA, 0x0, 0xC3 };
            }

            serPort.TransmitBinary(position);
        }
Exemple #6
0
        public void CommandBlind(string command, bool raw)
        {
            CheckConnected("CommandBlind");

            if (raw == false)
            {
                command += "~";
            }
            //number of characters to convert
            int comlen = command.Length;

            //convert command string into character array
            char[] commandChars = command.ToCharArray();

            //create byte array to fit bytes from character array
            byte[] byteArray = new byte[1 + (comlen * 2)];

            //convert each character to 2-byte, and copy the 2-byte into byteArray
            for (int i = 0; i < comlen; i++)
            {
                (BitConverter.GetBytes(commandChars[i])).CopyTo(byteArray, 1 + (i * 2));
            }
            byteArray[0] = Convert.ToByte(byteArray.Length);
            objSerial.TransmitBinary(byteArray);

            //string retval = objSerial.ReceiveTerminated("~");
            //retval = retval.Replace("~", "");
            //return retval;

            /***
             * CheckConnected("CommandBlind");
             * // Call CommandString and return as soon as it finishes
             * this.CommandString(command, raw);
             * // or
             * throw new ASCOM.MethodNotImplementedException("CommandBlind");
             * ***/
        }
        public static void ExecuteCommand(string command)
        {
            try
            {
                byte[] ende = new byte[1];
                ende = new byte[] { 0x0D };

                port.Transmit(command);
                Thread.Sleep(100);
                port.TransmitBinary(ende);
                tl.LogMessage("Sent Command", command);
            }
            catch
            {
                throw new ASCOM.NotConnectedException();
            }
        }
Exemple #8
0
 public void Halt()
 {
     tl.LogMessage("Halt", "Not implemented");
     // throw new ASCOM.MethodNotImplementedException("Halt");
     theSerial.TransmitBinary(LinShengStepMotor.cmd_stop);
 }
Exemple #9
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));
 }