Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ZFM20.h
- *
- * Created on: 04/10/2014
- * Author: Carlos Delfino <consultoria@carlosdelfino.eti.br>
- */
- /**
- * Classe de controle do Scanner ZFM20Series
- */
- class ZFM20Series {
- public:
- ZFM20Series(Stream *serial);
- void begin(ZFM20Address p_add = ZFM20_DEFAULT_ADDRESS);
- void sendPacket(ZFM20BasePackage p_pac);
- };
- ZFM20Series::ZFM20Series(Stream * p_serial) {
- ok = false;
- scanner = p_serial;
- address = ZFM20_DEFAULT_ADDRESS;
- }
- void ZFM20Series::begin(ZFM20Address p_add) {
- ZFM20Address old_add;
- if (p_add != getAddress()) {
- old_add = setAddress(p_add);
- }
- delay(500);
- ok = doHandshake();
- if (!ok && old_add) {
- if (ZFM20SERIES_DEBUG) {
- Serial.print(F("Begin Fail, return old add"));
- Serial.println(old_add, HEX);
- }
- setAddress(old_add);
- }
- }
- void ZFM20Series::sendPacket(ZFM20BasePackage p_pac) {
- (*scanner).write(1);
- uint16_t sizedata = p_pac.size - 0x02; // menos dois bytes do checksum
- ..... // here have more code, similar, which send more others numbers.
- scanner->flush();
- if (ZFM20SERIES_DEBUG) {
- Serial.println(F("sendPacket()"));
- Serial.println(F("************"));
- Serial.flush();
- }
- }
- ////// ZFMTest.ino
- #define ZFM20SERIES_DEBUG true
- #include "ZFM20Series.h"
- ZFM20Series scanner(&Serial3);
- void setup() {
- Serial.begin(57600);
- Serial.println(F("\n\nInicializando o Scanner"));
- Serial.print(F("Address: 0x"));
- Serial.println(scanner.getAddress(),HEX);
- Serial3.begin(57600);
- Serial3.write(0xFF); // here send correct value
- scanner.begin(); // here not send correct value
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement