Closed darkatrium closed 1 year ago
Have a look at the readVPWord function which posts back the data in the onHMIEvent function. If you get stuck get to me and I'll do a example.
added an example vp-read.ino not fully tested.
If you dont want to use the event
add these to the DWIN_Arduino.h file
u_int16_t readCMDLastBytes(); u_int16_t readVPBytes(long address);
and the 2 functions below to the DWIN_Arduino.cpp file
// read bytes from VP Address u_int16_t DWIN::readVPBytes(long address) { // 0x5A, 0xA5, 0x04, 0x83, hiVPaddress, loVPaddress, 0x01) byte sendBuffer[] = {CMD_HEAD1, CMD_HEAD2, 0x04, CMD_READ, (uint8_t)((address >> 8) & 0xFF), (uint8_t)((address)&0xFF),0x1}; _dwinSerial->write(sendBuffer, sizeof(sendBuffer)); return readCMDLastBytes(); } u_int16_t DWIN::readCMDLastBytes() { //* This has to only be enabled for Software serial
if (_isSoft)
{
((SoftwareSerial *)_dwinSerial)->listen(); // Start software serial listen
}
byte lastByte = -1;
byte previousByte = -1;
unsigned long startTime = millis(); // Start time for Timeout
while ((millis() - startTime < CMD_READ_TIMEOUT))
{
while (_dwinSerial->available() > 0)
{
previousByte = lastByte;
lastByte = _dwinSerial->read();
}
}
return( (previousByte << 8) + lastByte);
}
// test in your code.. Serial.println(hmi.readVPBytes(0x1000),HEX);
Hello. How i can read VP Data HiByte.
byte DWIN::readVPByte(long address) { // 0x5A, 0xA5, 0x04, 0x83, hiVPaddress, loVPaddress, 0x01) byte sendBuffer[] = {CMD_HEAD1, CMD_HEAD2, 0x04, CMD_READ, (uint8_t)((address >> 8) & 0xFF), (uint8_t)((address)&0xFF),0x1}; _dwinSerial->write(sendBuffer, sizeof(sendBuffer)); return readCMDLastByte(); } This i can read only Lo byte