Communication between Arduino and SharpCap

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
DavideB
Posts: 2
Joined: Sun Nov 06, 2022 2:21 pm

Communication between Arduino and SharpCap

#1

Post by DavideB »

Hi,
I was trying to understand how to send a command from an Arduino to Sharpcap with the aim to start an image acquisition (ideally each acquired frame should be triggered separately). Could it work by using a COM port?

Ideally I was looking for a tutorial that explains how to read data (eg. a specific character) sent from the Arduino through a COM port in Iron Python, and consequently do an action, but maybe that's too specific. :(

Sorry for the newbie question, I'm just starting to learn how to use sharpcap and scripting :)

Thanks in advance!

Davide
User avatar
admin
Site Admin
Posts: 13483
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Communication between Arduino and SharpCap

#2

Post by admin »

Hi,

yes, a serial port would be one way to do this - in Iron python you would need some code like this to create a SerialPort object

Code: Select all

clr.AddReference("System")
from System.IO.Ports import SerialPort
sp = SerialPort()
You can then configure it as required - see https://learn.microsoft.com/en-us/dotne ... mework-4.8 for details on how to configure, open and read from a serial port in .NET (which all translates to IronPython).

For instance

Code: Select all

sp.PortName = "COM1"
sp.BaudRate = 9600
...
Once you have the port up and running you can take the actions required in response to incoming messages - for instance if you have the camera in still mode in advance then you can use things like

Code: Select all

#Grab a frame from the camera and display it but do not save it
SharpCap.SelectedCamera.BeginFramingShot()
# As above, but also save the frame to an image file
SharpCap.SelectedCamera.CaptureSingleFrame()
Hope this helps,

Robin
DavideB
Posts: 2
Joined: Sun Nov 06, 2022 2:21 pm

Re: Communication between Arduino and SharpCap

#3

Post by DavideB »

Thanks Robin for your help.
I made a few tries but I still have to learn a bit more on how to code in python.
I will follow your links with more attention and let you know in case I’m in trouble.

Thanks a lot for now.

Davide
Post Reply