Esempio n. 1
0
        private void Write(byte value, byte[] halfAddress)
        {
            D4.Write((value & halfAddress[0]) > 0);
            D5.Write((value & halfAddress[1]) > 0);
            D6.Write((value & halfAddress[2]) > 0);
            D7.Write((value & halfAddress[3]) > 0);

            Enable.Write(true);
            Enable.Write(false);
            //Debug.Print("Wrote " + value.ToString());
        }
Esempio n. 2
0
        private void ProcessPacket(object sender, SerialDataReceivedEventArgs a)
        {
            byte[] inBuf = null;

            int available;

            do
            {
                available = _serial.BytesToRead;
            } while (available < 14);                       //wait for all bytes before operating on data

            inBuf = new byte[_serial.BytesToRead];
            _serial.Read(inBuf, 0, inBuf.Length);
            string Packet = new string(System.Text.Encoding.UTF8.GetChars(inBuf));

            int    RemoteChecksum = Int16.Parse(Packet.Substring(11, 3)); //extract sender's checksum
            int    LocalChecksum  = 0;
            string data           = Packet.Substring(3, 8);

            foreach (char digit in data)
            {
                LocalChecksum += digit;                                 //compute our checksum
            }
            LocalChecksum %= 1000;

            if (RemoteChecksum != LocalChecksum)
            {
                return;                                     //stop packet processing if checksums don't match
            }
            string packetType = Packet.Substring(0, 3);

            //if (packetType == "$$$")                        //do SID Protocol
            //{
            //    string command = data.Substring(0, 3);
            //    string value = data.Substring(3);

            //    switch (command) {
            //        case "ENV" :    //set voice envelope
            //            break;
            //        case "VFQ" :    //voice frequency
            //            break;
            //        case "VPW" :    //voice puslewidth
            //            break;
            //        case "FFQ" :    //filter frequency
            //            break;
            //        case "FRS" :    //filter resonance
            //            break;
            //        case "SVF" :    //voice filter mode
            //            break;
            //        case "VEN" :    //voice enable: on/off
            //            break;
            //        case "VWF" :    //voice waveform
            //            break;
            //        case "AMP" :    //set volume
            //            break;
            //        case "FMO" :    //filter mode (bp, hp, lp)
            //            break;
            //    }
            //}
            #region boring
            if (packetType == "###")                        //do Mayes Protocol
            {
                D0.Write(data[0] == '1' ? true : false);
                D1.Write(data[1] == '1' ? true : false);
                D2.Write(data[2] == '1' ? true : false);
                D3.Write(data[3] == '1' ? true : false);
                D4.Write(data[4] == '1' ? true : false);
                D5.Write(data[5] == '1' ? true : false);
                D6.Write(data[6] == '1' ? true : false);
                D7.Write(data[7] == '1' ? true : false);
            }
            #endregion
        }