void ofxModbusTcpClient::sendNextCommand(){
    if (commandToSend.size()>0){
        waitingForReply = true;
        
        //Set last function code
        lastFunctionCode = commandToSend[0].msg[7];
        
        //set transaction id
        WORD tx = getTransactionID();
        commandToSend[0].msg[0] = HIGHBYTE(tx); //Transaction High
        commandToSend[0].msg[1] = LOWBYTE(tx); //Transaction Low
        
        //load vector to local uint8_t
        uint8_t localByteArray[commandToSend[0].msg.size()];
        for (int i=0; i<commandToSend[0].msg.size(); i++){
            localByteArray[i] = commandToSend[0].msg[i];
        }
        
        //send command
        unsigned char * t = localByteArray;
        tcpClient.sendRawBytes((const char*)t, 6+commandToSend[0].length);
        
        //Log it
        sendDebug("Sent: "+commandToSend[0].debugString);
        
        //erase last command
        commandToSend.erase(commandToSend.begin());
    }
}
std::string SerializedTransaction::getFullText () const
{
    std::string ret = "\"";
    ret += to_string (getTransactionID ());
    ret += "\" = {";
    ret += STObject::getFullText ();
    ret += "}";
    return ret;
}
Beispiel #3
0
Json::Value STTx::getJson (int options, bool binary) const
{
    if (binary)
    {
        Json::Value ret;
        Serializer s = STObject::getSerializer ();
        ret[jss::tx] = strHex (s.peekData ());
        ret[jss::hash] = to_string (getTransactionID ());
        return ret;
    }
    return getJson(options);
}
Beispiel #4
0
// VFALCO This could be a free function elsewhere
std::string
STTx::getMetaSQL (Serializer rawTxn,
    std::uint32_t inLedger, char status, std::string const& escapedMetaData) const
{
    static boost::format bfTrans ("('%s', '%s', '%s', '%d', '%d', '%c', %s, %s)");
    std::string rTxn = sqlEscape (rawTxn.peekData ());

    auto format = TxFormats::getInstance().findByType (tx_type_);
    assert (format != nullptr);

    return str (boost::format (bfTrans)
                % to_string (getTransactionID ()) % format->getName ()
                % toBase58(getAccountID(sfAccount))
                % getSequence () % inLedger % status % rTxn % escapedMetaData);
}
void ofxModbusTcpClient::updateRegisters(int _id, int _startAddress, int _qty) {
    if (enabled) {
        if (_id<=numberOfSlaves && _id>0 && _qty<=125 && _qty>0) {
            uint8_t localByteArray[12];
            
            WORD tx = getTransactionID();
            WORD length = 6;
            WORD start = _startAddress-1;
            WORD qty = _qty;
            
            localByteArray[0] = HIGHBYTE(tx); //Transaction High
            localByteArray[1] = LOWBYTE(tx); //Transaction Low
            localByteArray[2] = 0x00; //Protocal Identifier High
            localByteArray[3] = 0x00; //Protocol Identifier Low
            localByteArray[4] = HIGHBYTE(length); //Length High
            localByteArray[5] = LOWBYTE(length); //Length Low
            localByteArray[6] = _id; //Unit Idenfifier
            localByteArray[7] = 0x03; //Function Code
            localByteArray[8] = HIGHBYTE(start); //Start Address High
            localByteArray[9] = LOWBYTE(start); //Start Address Low
            localByteArray[10] = HIGHBYTE(qty); //Qty High
            localByteArray[11] = LOWBYTE(qty); //Qty Low
            
            lastStartingReg = start;
            
            stringstream dm;
            dm<<"Reading Registers of "<<_id<<" Start:"<<_startAddress<<" Qty:"<<_qty;
            
            vector<uint8_t> lba;
            int sizeOfArray = sizeof(localByteArray) / sizeof(localByteArray[0]);
            for (int i=0; i<sizeOfArray; i++){
                lba.push_back(localByteArray[i]);
            }
            
            mbCommand c;
            c.msg = lba;
            c.length = length;
            c.timeAdded = ofGetElapsedTimeMillis();
            c.debugString = dm.str();
            commandToSend.push_back(c);
        } else {
            ofLogError("ofxModbusTCP IP:"+ip)<<"Read Registers Parameters Are Out Of Range";
        }
    }
}
Beispiel #6
0
Json::Value STTx::getJson (int) const
{
    Json::Value ret = STObject::getJson (0);
    ret[jss::hash] = to_string (getTransactionID ());
    return ret;
}