I have a custom HID device that, for testing pywinusb, returns anything that I send it. I think that I am sending the data correctly but I'm not receiving anything back. I tested the device with a terminal that can communicate with usb devices so, I know that when I send it something I get something back, ie i send [0x55, 0x00,...., 0x00] and I get 0x55,...,0x55 back.
when I run my code this is what i get:
[HID device (vID=0x0001, pID=0x0001, v=0x0001); Unipampa; Kaki, Path: \?\hid#vid_0001&pid_0001#6&2d07b355&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}]
None
This is the code that I'm running:
import sys
import pywinusb.hid as hid
def readData(data):
print(data)
return None
filter = hid.HidDeviceFilter(vendor_id = 0x0001, product_id = 0x0001)
hid_device = filter.get_devices()
device = hid_device[0]
device.open()
print(hid_device)
'''Send data'''
dataOut = device.find_output_reports()
buffer= [0xFF]*65
buffer[0] = 63
dataOut[0].set_raw_data(buffer)
dataOut[0].send()
''' Read data '''
dataIn = device.set_raw_data_handler(readData)
print(dataIn)
I'm just trying to get a simple write read to work.
Related
I want to retrieve XMLTYPE data from an Oracle table using cx_oracle.
the data looks like this:
<infos>
<Comment/>
<Observation>àéèç</Observation>
<Level>L3</Level>
<Duration/>
<Cause/>
<Depot> Haren </Depot>
<Resolution/>
</infos>
Here's my code:
#!/usr/bin/python
from __future__ import print_function
import cx_Oracle
# Connection to RTDIAG
try:
dsn_test = cx_Oracle.makedsn(host='xxxxx',port='1521',service_name='xxxxx')
con_test = cx_Oracle.connect(user='xxxx', password='xxxxx',dsn=xxxx)
except cx_Oracle.InterfaceError:
print ("Impossible to connect to the DB!")
print ("***exit script***")
quit()
ID_record = 1729
cursor = con_test.cursor()
query = """select a.content.getClobVal() from emb_log a where ID = :id and uncompleted_record=1
"""
cursor.execute(query,id=1729)
xml_retrieved = cursor.fetchone()[0].read() #string
print (xml_retrieved)
Here's what I get
<infos>
<Comment/>
<Observation>aeec</Observation>
<Level>L3</Level>
<Duration/>
<Cause/>
<Depot> Haren </Depot>
<Resolution/>
</infos>
The special characters contained within the XML child is not being retrieved proprely. They are converted in 'ascii like' characters.
Why and how to fetch the XML exactly the way it appears in the DB ?
Thank you.
Set your NLS environment. You will probably find it easiest to use
the
encoding
option when you connect.
for performance, you will want to fetch the CLOB via an OutputTypeHandler
I am trying to connect to a socket which provides a feed of stock prices (stockID,price), and then print it. The stream is endless. My problem is that I cannot print it.
To begin with, I create a connection:
con <- socketConnection(host = "88.99.38.191", port = 1337, open = "r")
then i set a variable reading all the lines.
data <- readLines(con,-1)
Then print(data)
the problem is that depending on the time gap between executing the connection and setting variable data, the latter receives a different number of values, and that's it.
I am trying to print somehow the entire stream. If I use
while (TRUE) { print(data) }
it just prints endlessly the data in loops.
Any idea how to implement that?
My ultimate goal is to calculate the moving average for each ID.
For those interested this is the answer.
con <- socketConnection(host = "88.99.38.191", port = 1337, open ="r",blocking = T,server=FALSE)
while(TRUE) {
data <- readLines(con,1)
print(data)
}
The problem with my initial approach was that I didn't use the blocking = T property for socketConnection. Further info can be found here.
I would like to print directly to an attached label printer without showing the print dialog.
I have searched to see if such a thing is possible but it seems it is not. So, I thought I would ask here in case someone knows a way to do it.
You have to save the Printer SetupString. Then the next time you go to print use that SetupString to initialize the PrinterSetup object. See actual code copied from working project below:
'Now print the mail barcode
dim ps as PrinterSetup
dim page as Graphics
ps = LabelPrinter //See below
if ps<>nil then
page = OpenPrinter(ps)
if page<>nil then
//send stuff to the printer here
Public Function LabelPrinter() as PrinterSetup
if gLabelSetup<>"" then //gLabelSetup is saved in preferences
dim ps as new PrinterSetup
ps.SetupString = gLabelSetup
return ps
else
return nil
end if
End Function
I am trying to send data from a VB6 program to a ticket printer Via TCP/IP. The only VB6 way I have found to try and do this is using the WinSock Control.
I use the following code to connect
WinSock.Protocol = sckTCPProtocol
WinSock.RemoteHost = txtIPAddress.Text
WinSock.RemotePort = txtPort.Text
WinSock.Connect
And then try and send the data as follows
WinSock.SendData ("<F8>" & txtPrint.Text & "<p>")
Everytime I try and do this, it fails because the Winsock.State is 6 (Connecting). This just stays at connecting and never connects or fails. I am able to connect to the printer using this IP/Port combo outside of VB6. Is there anything I may be doing wrong? Can the WinSock control do this?
In a .net program provided, this seems to be accomplished by doing the following:
CONNECT
client = new TcpClient(ip_address, 9100);
s = client.GetStream(); //s is System.Net.Sockets.NetworkStream
s.ReadTimeout = 500; //attempt to read for up to 0.5 seconds
sr = new StreamReader(s); //create read stream
sw = new StreamWriter(s); //create write stream
sb = new BinaryWriter(s); //create binary stream
sw.AutoFlush = true; //set write stream to flush data when < full buffer
SEND:
sw.WriteLine(command);
Thank you.
You are missing up concepts. I remember this from 15 years ago.
Winsock is for work with a protocol. You must know the printer protocol. Is not just sample text.
I'm trying to use PortAudio and libsndfile to play .wav files in exclusive mode on my Windows 7 machine, but I'm getting
error number -9984 "Incompatible host API specific stream info" .
I've filled out the PaWasapiStreamInfo struct as follows:
struct PaWasapiStreamInfo wasapiInfo ;
wasapiInfo.size = sizeof(PaWasapiStreamInfo);
wasapiInfo.hostApiType = paWASAPI;
wasapiInfo.version = 1;
wasapiInfo.flags = paWinWasapiExclusive;
wasapiInfo.channelMask = NULL;
wasapiInfo.hostProcessorOutput = NULL;
wasapiInfo.hostProcessorInput = NULL;
wasapiInfo.threadPriority = eThreadPriorityProAudio;
Then assigning the hostApiSpecificStreamInfo parameter and opening the stream via Pa_OpenStream as follows:
/* stereo or mono */
out_param.channelCount = sfinfo.channels;
out_param.sampleFormat = paInt16;
out_param.suggestedLatency = _GetDeviceInfo(out_param.device)->defaultLowOutputLatency;
out_param.hostApiSpecificStreamInfo = (&wasapiInfo);
err = Pa_OpenStream(&stream, NULL, &out_param, sfinfo.samplerate,
paFramesPerBufferUnspecified, paClipOff,
output_cb, file);
Have I missed a step?
Thanks,
Tyler
The technique you used to run the stream in exclusive mode worked for me. It may be the case that you're not opening a stream on a WASAPI device. Depending on your system configuration you may have DirectSound and WMME devices as well. The following code will verify whether the device referenced by index deviceIndexis a WASAPI device or not:
bool isWasapi = Pa_GetHostApiInfo(Pa_GetDeviceInfo(deviceIndex)->hostApi)->type == paWASAPI;
You also need to specify the same index in the out_param struct:
out_param.device = deviceIndex;
You did couple things I did not. In your example you tried to set the thread priority, but PortAudio documentation states that the following line:
wasapiInfo.threadPriority = eThreadPriorityProAudio;
will have no effect because you didn't not set the paWinWasapiThreadPriority bit in wasapiInfo.flags. By the same rule it is unnecessary to explicitly set the other varaibles to null. To fix this set wasapiInfo.flags as follows:
wasapiInfo.flags = (paWinWasapiExclusive|paWinWasapiThreadPriority)
This should enable exclusive mode and cause the threadPriority variable to take effect.