I have one hardware which uses Asynchronous serial interface protocol, 9600 baud rate, #Start bits 1,#Data bits 8, #Stop bits 1, Parity None. When I am communicating my hardware with a python script using a cp2102 device that time hardware doesn't respond but when I try to communicate the same hardware with Arduino nano then it works properly.
Working Arduino code:
void volt_currentTest()
{
Serial.write(0xDD);
Serial.write(0xA5);
Serial.write(0x03);
Serial.write(0x00);
Serial.write(0xFF);
Serial.write(0xFD);
Serial.write(0x77);
while(c != 0x77)
{
if(Serial.available())
{
if((c = Serial.read()) != -1)
{
Serial.println(c , HEX);
d[i] = c;
i++;
}
}
}
}
Python code:
import serial
ser = serial.Serial(
'COM9', 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE
)
'''data = b'\xdd\xa5\x03\x00\xff\xfd\x77'
ser.write(data)'''
ser.write(b'\xDD')
ser.write(b'\xA5')
ser.write(b'\x03')
ser.write(b'\x00')
ser.write(b'\xFF')
ser.write(b'\xFD')
ser.write(b'\x77')
'''
ser.write('\xDD\r\n'.encode())
ser.write('\xA5\r\n'.encode())
ser.write('\x03\r\n'.encode())
ser.write('\x00\r\n'.encode())
ser.write('\xFF\r\n'.encode())
ser.write('\xFD\r\n'.encode())
ser.write('\x77\r\n'.encode())
'''
while True:
response = ser.read()
'''response = ser.readline()
'''
print(response)
So Anyone having an idea why it's not working .....