satspares / DWIN_DGUS_HMI

Arduino Libabry for DWIN DGUS T5L HMI Displays
15 stars 3 forks source link

Read VP WordData #1

Closed darkatrium closed 1 year ago

darkatrium commented 1 year ago

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

satspares commented 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.

satspares commented 1 year ago

added an example vp-read.ino not fully tested.

satspares commented 1 year ago

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 defined(DWIN_SOFTSERIAL)

if (_isSoft)
{
    ((SoftwareSerial *)_dwinSerial)->listen(); // Start software serial listen
}

endif

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);