sending data from python to c# - c#

i have a chart pattern recognition program using neural networks written in python .instead of porting the whole code to C# ,i decided it was better to only send certain bits indicating the following :
Buy=1,Sell=-1,Do nothing=0
once they are in C-sharp ,i could relay them to a third party program (multicharts) which would continuously call the C# dll function and receive these values after a certain time interval .
my question is ,is there a way to relay these bit's to C# and pack all of this in a dll ,which gets read by the 3rd party program ?
the whole reason i want to port to C# is because multicharts only reads in dll's and i dont think python has them.
sorry for being naive ,i don't have very good grip on C# .

Your options are as follow,
Use a TCP socket, bind it to a port and listen for data in C# while the python application sends all data to it. C# has some great features for sockets such as System.Net.TcpClient
and
System.Net.TcpServer.
Your other option is that if the C# application only needs to be run once it receives information from the python program and then it can die, you could have the python program start the C# one and pass it parameters containing the information that you need transmitted.
By the looks of it your question only asked if there was a way to communicate, these are probably the best two. Please let me know if I can help anymore.

Related

How do I let multiple consoles share input between one another?

What I'm Trying to Achieve
I'm attempting to build a console game that has multiple console windows that would be displaying inventory, status effects, current map, and health. Another console would be the main one that gathers input to effect the other consoles. The reason I want to do it this way is so that the other consoles can be updating their "graphics" (or text) without disturbing the input flow.
What I've Tried So Far
So far, I've attempted to use System.IO's File, FileStream, StreamWriter, and StreamReader to communicate between the consoles via text files. The problem I've ran into is that, when the main console (the input console) is attempting to write inputs to a file--which is communicating with another console (the "graphics" console)--it throws an error because the "graphical" console is trying to read the input of the file (or vice versa).
I figured that making the FileStream's FileAccess be Readable would do the trick, but I ran into the same issue.
I think I could get this to work if I could communicate between the consoles to tell each other that one is done writing to or reading the file... kind of like a back and forth... "I'm writing to the file... okay, I'm done" "I'm reading the file... okay, I'm done" and the cycle continues...
So, in summary, I suppose, my question is how can I communicate between two consoles using files?
Possible Solutions I could try learning SQL, but I don't know if I'd end up running into the same issue... so, if I must learn SQL for this project, I suppose, that'd be my last option.
Thank you!
IPC (inter process communication) is the keyword you're looking for.
There are multiple ways to do IPC, e.g. shared memory, named pipes or similar. .NET has an IpcChannel which uses TCP or a named pipe if the destination is on the local PC.

msp430g2553 How to share datas from board to VS for C#

I wanna make a project with msp430g2553 like use heat sensor and want to read the datas from the sensor on the program that I write on C#. I know the basics of C# I can build form applications and also can use msp430 boards but i don't know how to link them each other. I ask that how can I link each other?
But I want to write the all codes C# and msp430. I don't want to prepared GUI.
I searched a little bit there is something like GIOP to do that but there is information little about that. Can you help me please.
And thanks for helps.
I agree with jdweng that you should use the UART feature from the Launchpad development board. Just find the guide for your board and look for the basic demo that outputs the "hello world" message to the serial port with connection to your PC using a terminal program such as Putty in serial mode. Then write a simple program in C# to replace the terminal program and establish that your program can read the "hello world" from the serial port. From there, you then need to change the demo to reading the sensor. I suggest you first emulate reading data from the sensor (i.e., must make up some data) and output that to the serial port, then finish your C# program with that data. Then find a suitable sensor and read the datasheet for the part. You may need to use another interface (such as SPI or I2C) to read form the sensor. This will depend on the sensor you choose. Best of luck!

Send data from Python to C#

I'm trying to send data from a python script to my c# application using a standard input stream. I also need to eventually send data back from my c# application to the another python script. I first tried to do this with a UDP Connection which works fine for a couple lines, but I have a fair amount of data to send (a few thousand lines) and a requirement for data integrity which UDP cannot provide. I could also write to a file, but that seems very inefficient.
One last restriction is that while my two applications are related I cannot setup a direct connection between them using something like IronPython as they are both spawned separately by a 3rd party application.
This is what I am currently trying, but it is not working. Similar to this question: Passing data between Python and C# without writing a file
p = subprocess.Popen(C_SHARP_EXECUTABLE_FILE_PATH, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate(blob)
On my C# side I'm not entirely sure how to read this data, but I've tried using things like a loop around this:
Console.ReadLine()
or getting the standard input and reading from it directly using:
Console.OpenStandardInput();
The current issue is that as soon as I call p.communicate my Python script gets locked and doesn't proceed. If it's waiting for the line to be read, what do I need to do to make it stop waiting? I tried only providing the stdin parameter, but that didn't help.

Transferring binary file over through RS232 using C#

I am looking to transfer a binary file via RS232. I need to do this to 5000 different devices (no joke). I could do them one-by-one through a terminal program but that will take a lot of time.
So, I am writing a C# program that will be able to automate the process. I am looking at using XMODEM protocol and command line parameters to start the process. I have been looking for this for a few hours now and far my results have turned up little. I tried using uCON but that takes some sort of scripting language.
I was wondering if anyone in the community here might know of a solution to transfer a file over RS232 and program it in C#. Whether it is from a protocol (XMODEM) or a program that accepts command line or some other custom solution, doesn't really matter to me.
Ok so I was able to confirm that the code found on the website( ghielectronics.com/community/codeshare/entry/825) was able to work. The issue was was that I did not know how long it would take the computer to transfer the file. I thought that it would be quick. However, after further testing, it actually takes about 30 sec to 1 min depending on the file size.
This C# code snippet allows anyone to transfer a binary file over the Serial Port using the XMODEM protocol. This is done in code and a terminal is not needed which fits the requirements that I needed for the project.

GSM modem library

I'm looking for SMS library that is written in c#, anyone the best library for it and it's free ? I can find more than 1 in Linux, but I'm can't found anything that is written in c# and free
Most GSM modem will come with a library of it's own. You don't really need the library to be written in C#. Generally it will be in dll or exe. If it's a dll written using C++, you can still call it's function via p/invoke. You just need to know the function signature in order to send and retrieve data from it properly. Check the documentation. If it's an exe, most likely it commandline based, then you can call it by using Process.Start() and putting in what ever you want to send via the argument.
Check out GSMComm.
http://www.scampers.org/steve/sms/index.htm

Categories

Resources