示例#1
0
        public void InitializeSharedMemory()
        {
            //MyDataStructure data = new MyDataStructure();
            //data = memCommand.Get();

            MyDataStructure2 data2 = new MyDataStructure2();

            data2 = memCommand2.Get("InitializeSharedMemory");

            //

            checkBoxBadCRC1.Checked = true;
        }
示例#2
0
    public void Send(byte[] comByte, int siz)
    {
        // Test Master
        master_flag = "";
        switch (_PortName)
        {
        case "Port1":

            if (siz == 17)
            {
                // port 1    0x01, 0x04, 0x14D8, 0x0002, CRC1, CRC2   // Temp
                if (comByte[0] != 0x01)
                {
                    master_flag = "Bad";
                }
                if (comByte[1] != 0x10)
                {
                    master_flag = "Bad";
                }
                if (comByte[2] != 0x10)
                {
                    master_flag = "Bad";
                }
                if (comByte[3] != 0x01)
                {
                    master_flag = "Bad";
                }
                if (comByte[4] != 0x00)
                {
                    master_flag = "Bad";
                }
                if (comByte[5] != 0x04)
                {
                    master_flag = "Bad";
                }
                if (comByte[6] != 0x08)
                {
                    master_flag = "Bad";
                }
            }
            if (siz == 8)
            {
                // port 1    0x01, 0x04, 0x14D8, 0x0002, CRC1, CRC2   // Temp
                if (comByte[0] != 0x01)
                {
                    master_flag = "Bad";
                }
                if (comByte[1] != 0x04)
                {
                    master_flag = "Bad";
                }
                if (comByte[2] != 0x00)
                {
                    master_flag = "Bad";
                }
                if (comByte[3] != 0x01)
                {
                    master_flag = "Bad";
                }
                if (comByte[4] != 0x00)
                {
                    master_flag = "Bad";
                }
                if (comByte[5] != 0x04)
                {
                    master_flag = "Bad";
                }
            }

            break;

        case "Port2":
            // port 2    0x01, 0x04, 0x14D8, 0x0002, CRC1, CRC2   // Temp
            if (comByte[0] != 0x01)
            {
                master_flag = "Bad";
            }
            if (comByte[1] != 0x04)
            {
                master_flag = "Bad";
            }
            if (comByte[2] != 0x14)
            {
                master_flag = "Bad";
            }
            if (comByte[3] != 0xD8)
            {
                master_flag = "Bad";
            }
            if (comByte[4] != 0x00)
            {
                master_flag = "Bad";
            }
            if (comByte[5] != 0x02)
            {
                master_flag = "Bad";
            }
            break;
        }


        MyDataStructure2 data2 = new MyDataStructure2();

        data2 = _memCommand2.Get("Send");
        bool noResp = false;

        ack_msg   msg_ack_msg;
        data_resp data_resp_msg;


        frameW++;
        //Output packet
        if (IsOpen)
        {
            if (master_flag == "Bad")
            {
                comByte_inx = _mem[0].Get();
            }
            test1++;
            switch (_PortName)
            {
            case "Port1":
                comByte_inx = _mem[0].Get();


                if (siz == 17)
                {
                    // Pack Packet
                    msg_ack_msg.addr   = 0x01;          // Address
                    msg_ack_msg.fc     = 0x10;          // Function Code
                    msg_ack_msg.staddr = 0x0110;        // Data Length in Bytes
                    msg_ack_msg.Qor    = 0x0400;        // Data Length in Bytes
                    msg_ack_msg.crc1   = 0;             // CRC - Hi
                    msg_ack_msg.crc2   = 0;             // CRC - Low
                    buffer_out         = CRC_msg_ack_msg(msg_ack_msg, data2.Port1_badCRC);
                }
                if (siz == 8)
                {
                    // Pack Packet
                    data_resp_msg.addr   = 0x01;        // Address
                    data_resp_msg.fc     = 0x04;        // Function Code
                    data_resp_msg.staddr = 0x08;        // Data Length in Bytes
                    data_resp_msg.data1  = data2.Port1_b01;
                    data_resp_msg.data2  = data2.Port1_b02;
                    data_resp_msg.data3  = data2.Port1_b03;
                    data_resp_msg.data4  = data2.Port1_b04;
                    data_resp_msg.data5  = data2.Port1_b05;
                    data_resp_msg.data6  = data2.Port1_b06;
                    data_resp_msg.data7  = data2.Port1_b07;
                    data_resp_msg.data8  = data2.Port1_b08;
                    //data_resp_msg.data9 = data2.Port1_b09;
                    //data_resp_msg.data10= data2.Port1_b10;



                    data_resp_msg.crc1 = 0;          // CRC - Hi
                    data_resp_msg.crc2 = 0;          // CRC - Low
                    buffer_out         = CRC_data_resp_msg(data_resp_msg, data2.Port1_badCRC);
                }
                // Add CRC to Packet


                noResp = data2.Port1_noResp;
                break;

            case "Port2":
                comByte_inx = _mem[0].Get();
                noResp      = data2.Port2_noResp;
                break;
            }



            // Get NoResponse from SharedMemory
            str2 = ByteToHex(buffer_out);
            if (!noResp)
            {
                try
                {
                    //Console.Write("Send: 1(" + test1 + ") " + str2 + "\n");
                    if (siz == 17)
                    {
                        _serialPort.Write(buffer_out, 0, 8);            // serial port write
                    }
                    if (siz == 8)
                    {
                        _serialPort.Write(buffer_out, 0, 13);            // serial port write
                    }
                    str = DateTime.Now.ToString("dd-MMM-yy hh:mm:ss.fff");
                }
                catch (Exception err)
                {
                    Console.Write("Exception Thread: _serialPort.Write\n");
                    Console.WriteLine(err);
                }
                if (master_flag == "Bad")
                {
                    DataReceived(str + "# " + frameW + ") Tx: X " + str2);   // Write to GUI
                }
                else
                {
                    DataReceived(str + "# " + frameW + ") Tx:   " + str2);   // Write to GUI
                }
            }
            MasterStatus(master_flag);  // Control LSD on GUI
        }
    }