SpiDevice read, write and transfer - c#

Playing with Windows IoT on a raspberry pi 3 and I am trying to communicate to an Adafruit RFM69HCW.
I have connected to the device via SPI and not matter what I do I can't seem to get the pi to read anything from the device registers.
The one thing I wanted to know is what exactly does SpiDevice.Read(), Write(), TransferSequential() and TransferFullDuplex() do?
I know the obvious basics but I am after the steps it performs for each function.
Reason I ask is because in the spec of the RF module it says when communicating you have to set the CS pin to low, send the command and then set the CS pin back to High. Does, for example, SpiDevice.Read() do this already?
I have been converting both an Arduino library and a Python Raspberry Pi code so I know about doing the Hard Reset first.
Link to the spec if anyone interested.RFM69HCW-V1.1.pdf

Reason I ask is because in the spec of the RF module it says when
communicating you have to set the CS pin to low, send the command and
then set the CS pin back to High. Does, for example, SpiDevice.Read()
do this already?
Yes, you are right. I test the SPIAccelerometer sample and get the following sequence diagram. The yellow line is chip select and the other is clock line. As you can see, when writing and reading the CS is set to low.(The wave shape is ugly because my scope has low performance.)

Related

How to stream audio to a specific output device?

Have been struggling with finding a way to stream audio, from a file or web, to a specific output device, not just the default one. Tried using mciSendString and while the open command does accept a device id/filename I haven't found a way to make use of it, am not even sure if this is what I am looking for or not, but considering it says ... or the filename of the device driver am guessing yes(?), but correct me if I am wrong, and this isn't a specify your output device type parameter.
If it is the correct thing then how do you enumerate the installed device drivers, have looked into the IMMDevice interface because it seamed like it could have the file names stored in the registry, but non of the output device registry keys had a driver filename type value entry, or at least I haven't found one.
So my question is, how would you go about streaming audio to a specific output device, it doesn't have to be done through mciSendString, that's just something I looked into as it's one of the most talked about function when it comes to playing audio.
Note: please do not recommend me 3rd party libraries like NAudio, the reason I am asking this question is not get recommendations for libraries, otherwise I would have already used one and would have never written this, have just seen a lot of answers be like: Use {LibName}, it has what you want or something along those lines.
In case what's written is odd or incorrectly worded in places, basically this is what the end goal should be:
Installed Output Devices:
- Output1
- Output2
- Output3
Method For Playing:
//will play x.mp3 through output device 1
PlayAudio(output: "Output1", mp3File: "x.mp3");
//will play x.mp3 through output device 2
PlayAudio(output: "Output2", mp3File: "x.mp3");
//will play x.mp3 through output device 3
PlayAudio(output: "Output3", mp3File: "x.mp3");
You seem to be looking for this API:mciSendCommand()
To set the WaveAudio device (soundcard) used by the Multimedia
Control, you must use the mciSendCommand API. The Multimedia Control
does not directly provide a method to let you set the device used for
playing or recording.
Call mciSendCommand() with MCI_SET & MCI_WAVE_SET_PARMS
setting wOutput to the desired playback device's ID.
Then get IDDevice for mciSendCommand() via
mciGetDeviceID("waveaudio")
Its not 100% clear what wOutput wants, its probably the same ID as returned by waveOutGetDevCaps()
I am just a porter.
Please refer:
https://stackoverflow.com/a/13320137/11128312
https://stackoverflow.com/a/10968887/11128312

DHT11 + Arduino UNO + Raspberry pi3 + Windows Remote Arduino

I need to read with C# UWP App, a DHT11/DHT22 sensor to get temperature and the arduino is conected to an Arduino UNO.
Can I use "digitalRead" at sensor PIN and converte the values using C# library
'sensors.dht'? Or I need to change the FirmataStandard sketch to include dht library and receive the values "cleaned"?
Thanks very much!
In theory, your plan is possible utilizing Windows Remote Arduino.
But currently, there is no official solution for your user case.
So you may need do some work by yourself. You need modify GPIO OneWire DHT11 library to fit your solution, such as, replace Windows::Devices::Gpio::GpioPin::Read() with Microsoft::Maker::RemoteWiring::RemoteDevice::digitalRead() and so on. Also note the time sequence due to DHT11/22 datasheet.
Finally, you may need sufficient test to ensure this solution works as expected.

Intercept and modify USB packets

The project is as follows;
I would like to create an application that will be able to see packets going to a USB device. When a certain bit of data that is known is sent to the device, the returning data will be intercepted and modified before the application requesting it, gets it. I have used a USB sniffer to see the packets being sent and I know exactly what bits need to be changed. My two questions are;
Is this a possible software solution?
Will this have to be a hardware solution?
Additional Information –
The USB device uses a FTDI245R chip for communication. I know the VID and PID of the device.
I have experience programming in vb.net and C# but I have never done anything with USB
I would like the application to be able to have a number entered and changed to hex data and that is what would be sent to the device. The number being entered would be changed frequently.
Any input is appreciated.
It sounds to me like you want an upper filter driver to the FTDI driver. I don't know what class or type of device you are using or if it has a vendor specific driver or not, but here is a sample that shows how to create an upper filter to a vendor specific driver. This example uses the OSRUSBFX2 device and sample driver in the WDK, you'll want to change the code to work and interface with the FTDI driver instead.

Using C# to detect a printer's power status

I did a lot of search and it comes with nothing.Such as below:
c# check printer status
how do i check if a printer is installed and ready using C#?
I tried all the code I found in here but none of them can tell the status of a printer's power is on or off.
The printer is always plugged in and sometimes it's powered off, so I need to make sure it's powered on and then do the print job.
Real need some help here!
question update
the windows still send the print job to print spool when my printer is off, I don't need this, because my client sometimes will deliberately turn off the printer to avoid print something that he don't need. but windows still send it to spool, when my client turn on the printer again, it prints the thing that exactly he want to avoid.
The legacy code uses kernel32.dll's CreateFile function to open LPT1 as a file and directly write string to it to accomplish then printing function. It got no way to know the status of the printer, it just write string to the parallel port. so when the printer is off, the write function got no return, hence the following code after that will never get executed.
hopefully u can understand what I am trying to do here. I want to avoid the situation to print when the printer is off.

Datalogic Barcode/Weight Scanner

Could anyone please give me any idea as to where to start my coding in order to get data from OPOS(Datalogic Magellan device) weighting and barcode scanning in C#?? For example, what library and what function I should be using for this case. I am clueless as I have already spent numerous of hours searching for an answer online. Not even came close online.
I don't know any api that I can use to get the weight and barcode for the usb device into my C# program.
I am currently using Datalogic scale. I tried the build-in windows reader but it didn't read in any data from the device.
First off, I used the Microsoft.PointOfService library which can directly create connection to most of the opos base machine. And make sure you have your Logical Device Name right! Very Very important. This is NOT any normal name you found in your regedit, it MUST be define manually by yourself inside the opos adk program that you installed along with the opos machine.
Then you can pass in the name as usual in your C# program.
For example: you set USB_Scale as your logical device name inside OPOS program
in C#
this.myDevice = explore.GetDevice("Scale", "USB_Scale");
Note: Make sure you set claim to 1000; It might not work if you didn't do so.
Also : this.myScale = ((Scale)explore.CreateInstance(myDevice)); <- this might help~
The rest is just straight forward.

Categories