Python 3.5 - ctypes - create string buffer for Citect API

Andrzej Gośliński

I would like to access our Citect SCADA system from external script in Python. I found some example code here: https://github.com/mitchyg/Random/blob/master/pyctapi/src/pyctapi.py

When I run this fragment of code:

def ct_tag_read(self, tag_name):
    buffer = create_string_buffer('\000' * 32)
    ok = windll.CtApi.ctTagRead(self.hCTAPI, tag_name, byref(buffer), sizeof(buffer), None)

    return buffer.value

I get this error:

line 63, in create_string_buffer
raise TypeError(init)
TypeError:  

I am using Python 3.5.

Here is description of Citect API function ct_TagRead:

http://www.citect.schneider-electric.com/webhelp/vijeo740/Content/ctTagRead.html

Andrzej Gośliński

OK, first of all i mixed up arguments for ctCicode and ctTagRead so code should look like(without ",None" argument):

def ct_tag_read(self, tag_name):
    buffer = create_string_buffer('\000' * 32)
    ok = windll.CtApi.ctTagRead(self.hCTAPI, tag_name, byref(buffer), sizeof(buffer))
    if ok == False:
        print("Unable to read TAG")
        return

return buffer.value

I switched to python 2.7 and everything works fine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python ctypes how to write string to given buffer

From Dev

Python ctypes passing string pointer / buffer

From Dev

ctypes string buffer in scope

From Dev

ctypes from buffer - Python

From Dev

Python3, ctypes API and Enum

From Python

create_string_buffer and string.join error from python 2 to python 3

From Dev

How to print contents of ctypes string buffer

From Dev

Python 3 ctypes call to a function that needs an indirect reference to a buffer through another structure

From Dev

Python 3 : TypeError: Type str doesn't support the buffer API

From Dev

python3 Type str doesn't support the buffer API

From Dev

Python ctypes: how to define a callback having a buffer pointer and a length in argument?

From Dev

Python `ctypes` - How to copy buffer returned by C function into a bytearray

From Dev

Python packet sniffer using ctypes crashes when copying socket buffer

From Dev

edit the buffer of a Ctypes structure

From Dev

Create an array of pointers in Python using ctypes

From Dev

Create a buffer and assign it a pointer in Python

From Dev

Forcing EnumChildWindows to use a global buffer, rather than a local buffer (Python ctypes)

From Dev

Python 3 Create md5 hash

From Dev

C Method returning string to Python via ctypes

From Dev

Setting up a WindowsHook in Python (ctypes, Windows API)

From Dev

TypeError: expected string or buffer | Python

From Dev

python docopt: "expected string or buffer"

From Dev

python decopt: "expected string or buffer"

From Java

Python TypeError: expected string or buffer

From Dev

TypeError: expected string or buffer in Python

From Java

Buffer function for python 3+

From Dev

Ctypes - How to parser buffer content?

From Dev

Python SocksiPy package error: TypeError: Type str doesn't support the buffer API for string?

From Dev

Write buffer in C which is allocated in python using ctypes, and read back again in python

Related Related

  1. 1

    python ctypes how to write string to given buffer

  2. 2

    Python ctypes passing string pointer / buffer

  3. 3

    ctypes string buffer in scope

  4. 4

    ctypes from buffer - Python

  5. 5

    Python3, ctypes API and Enum

  6. 6

    create_string_buffer and string.join error from python 2 to python 3

  7. 7

    How to print contents of ctypes string buffer

  8. 8

    Python 3 ctypes call to a function that needs an indirect reference to a buffer through another structure

  9. 9

    Python 3 : TypeError: Type str doesn't support the buffer API

  10. 10

    python3 Type str doesn't support the buffer API

  11. 11

    Python ctypes: how to define a callback having a buffer pointer and a length in argument?

  12. 12

    Python `ctypes` - How to copy buffer returned by C function into a bytearray

  13. 13

    Python packet sniffer using ctypes crashes when copying socket buffer

  14. 14

    edit the buffer of a Ctypes structure

  15. 15

    Create an array of pointers in Python using ctypes

  16. 16

    Create a buffer and assign it a pointer in Python

  17. 17

    Forcing EnumChildWindows to use a global buffer, rather than a local buffer (Python ctypes)

  18. 18

    Python 3 Create md5 hash

  19. 19

    C Method returning string to Python via ctypes

  20. 20

    Setting up a WindowsHook in Python (ctypes, Windows API)

  21. 21

    TypeError: expected string or buffer | Python

  22. 22

    python docopt: "expected string or buffer"

  23. 23

    python decopt: "expected string or buffer"

  24. 24

    Python TypeError: expected string or buffer

  25. 25

    TypeError: expected string or buffer in Python

  26. 26

    Buffer function for python 3+

  27. 27

    Ctypes - How to parser buffer content?

  28. 28

    Python SocksiPy package error: TypeError: Type str doesn't support the buffer API for string?

  29. 29

    Write buffer in C which is allocated in python using ctypes, and read back again in python

HotTag

Archive