1

I Just want to send hex byte array using arduino to an external device.

so at first i tried the device using c# and my pc. here is my sample code that works fine:

_serial.BaudRate = 9600;
_serial.PortName = "COM2";
_serial.Open();
byte[] _bytesToSend = new byte[9] { 0x05, 0x30, 0x30, 0x31, 0x2C, 0x30, 0x30, 0x30, 0x03 };
_serial.Write(_bytesToSend, 0, _bytesToSend.Length);

the problem occurs when i translate this to arduino software serial like this:



    SoftwareSerial softSerial1(3, 4); 
    SoftwareSerial softSerial2(5, 6); 

    void setup(){
      Serial.begin(9600);
      softSerial1.begin(9600);
      softSerial2.begin(9600);
    }



    void loop(){

        String sample1 = "";
        byte bytes_to_send[9] =  { 0x05, 0x30, 0x30, 0x31, 0x2C, 0x30, 0x30, 0x30, 0x03 };
        softSerial1.listen();
        softSerial1.write(bytes_to_send,9);
        delay(50); 

        if(softSerial1.available()){

            sample1 = softSerial1.readString();
            Serial.println("Sample1:"+sample1);

         }else{
            Serial.println("Serial 1 Empty"); 
        }

    }

i got no answer from device for the above code

  • the snippets you shared are not enough to see whats happening here,it would be helpful, if you could share the `setup` function and ports initializations part. – user3473830 Sep 21 '14 at 12:51

0 Answers0