Some Fixes and Additions

This commit is contained in:
2015-04-06 18:02:26 +02:00
parent 6bf3ddd8f0
commit 41e9b0a6b1
2 changed files with 62 additions and 6 deletions

View File

@@ -439,6 +439,65 @@ ex_WriteBytes (PyObject *self, PyObject *args)
/*
* Write Bytes
*/
static PyObject *
ex_SetBit (PyObject *self, PyObject *args)
{
/*
* Set a bit to PLC memory area "area", data block DBnum.
* If a buffer pointer is provided, data will be copied into this buffer.
* If it's NULL you can get your data from the resultPointer in daveConnection long
* as you do not send further requests.
*
* TODO Length check
*
* Area
* daveP 0x80
* daveInputs 0x81
* daveOutputs 0x82
* daveFlags 0x83 Merker
* daveDB 0x84 data blocks
* daveDI 0x85 instance data blocks
* daveLocal 0x86 not tested
* daveV 0x87 don't know what it is
* daveCounter 28 S7 counters
*
* DB
* start
* len
*/
PyObject *selfobj;
PyObject *values;
int iArea, iDB, iStart, iBitAdr;
int res;
char * cvalues;
daveConnection *dconn;
daveSetDebug (daveDebugPrintErrors);
//Extract area, db, start, len from Arguments
Py_INCREF (args);
if (!(PyArg_ParseTuple (args, "Oiiii", &selfobj, &iArea, &iDB, &iStart, &iBitAdr)))
return NULL;
Py_DECREF (args);
dconn = PyCObject_AsVoidPtr (PyObject_GetAttrString (selfobj, "daveconaddr"));
res = daveSetBit (dconn, iArea, iDB, iStart, iBitAdr);
if (res != 0)
{
printf ("SetBit failed! (%d)\n", res);
return PyInt_FromLong (res);
}
Py_INCREF (Py_None);
return Py_None;
}
/*
* U32 to FloatRequest
@@ -484,7 +543,7 @@ static PyMethodDef pydaveMethods [] = {
{"WriteBytes", ex_WriteBytes, METH_VARARGS, "Write Bytes to PLC"},
//{"WriteManyBytes", ex_WriteManyBytes, METH_VARARGS, "Write Bytes to PLC"},
//{"WriteBit", ex_WriteBit, METH_VARARGS, "Write Bit to PLC"},
//{"SetBit", ex_SetBit, METH_VARARGS, "Set Bit on PLC"},
{"SetBit", ex_SetBit, METH_VARARGS, "Set Bit on PLC"},
//{"ClrBit", ex_ClrBit, METH_VARARGS, "Clear Bit on PLC"},
{"PrepareReadRequest", ex_PrepareReadRequest, METH_VARARGS, "Prepare Read Request"},
{"AddVarToReadRequest", ex_AddVarToReadRequest, METH_VARARGS, "Add Variable to Read Request"},

View File

@@ -41,11 +41,11 @@ if __name__ == '__main__':
pass;
sys.exit (0)
r_server = redis.Redis ('176.9.41.147')
r_server = redis.Redis ('localhost')
#for _id, _name, _proto, _addr, _port, _mpi, _rack, _slot in [[5,'H6L2', 'ISO_TCP', '192.168.100.73', 102, 2, 0, 4]]:
#for _id, _name, _proto, _addr, _port, _mpi, _rack, _slot in [[5,'H6L1', 'ISO_TCP', '192.168.100.73', 102, 3, 0, 4]]:
clients = [
[1,'Centrotherm', 'IBH_Link', '192.168.125.201', 1099, 2, 0, 4, 0, 0, 0, 0, 0],
[1,'ABP-Buero', 'IBH_Link', '192.168.11.99', 1099, 4, 0, 4, 0, 0, 0, 0, 0],
]
conns = {}
for client in clients:
@@ -86,8 +86,5 @@ if __name__ == '__main__':
r_pipe.execute ()
conns [_id].DisconnectPLC ()