Synchronizing two matlab scripts on two devices

조회 수: 6 (최근 30일)
Chandler Johnston
Chandler Johnston 2022년 11월 20일
댓글: Walter Roberson 2022년 11월 20일
Hi folks,
I am working on a personal project that requires two devices running a matlab script to remain sychronized. My hope is that device 1 can complete a task then let device 2 know that it is done so device 2 can complete its task, then visa versus, repeating.
This sychronization could be simply done using the time because the tasks are periodic in nature, however I am looking to add some robustness to my script so that if one device is stopped, the other one will also automatically stop. I have considered using a file to load and save states to, but I think that will get messy with two devices tryng to read and write to the same file.
Is there a way to share a variable between devices or an easy way to send messages? I briefly looked into bluetooth, but I feel that there must be a simpler way to do this that I am not aware of.
Any ideas are appreciated,
Thank you!
  댓글 수: 1
Chandler Johnston
Chandler Johnston 2022년 11월 20일
Just to clarfiy, I'm looking to achieve:
Device 1 does something... Device 1 is done and lets device 2 know it can go...
Device 2 sees it can go and does something... Device 2 is done and lets device 1 know it can go...
Device 1 sees it can go and does something... Device 1 is done and lets device 2 know it can go...
So on and so forth

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2022년 11월 20일
If the devices support RS232 and you have one of the increasingly-rare true serial ports, then you can use serialport() and configure timeouts, and have the devices send messages over serial to the host that relays to the other device (or send directly between devices.)
If the devices support serial-over-USB then you can use serialport(), very similar to the above (but differences in latency.)
If you have the Instrument Control Toolbox you could consider using udpport() and related functions, or you could consider tcpserver() and tcpclient()
If you do not have Instrument Control Toolbox, then you could consider using tcpclient() -- but the devices would have to be prepared to act as tcp servers.
There is a File Exchange Contribution https://www.mathworks.com/matlabcentral/fileexchange/345-tcp-udp-ip-toolbox-2-0-6 that can act as a tcp server without Instrument Control
Depending on what the devices are, you might possibly be able to configure them with a Digital Pin wire or SPI communication and have them trigger each other.
  댓글 수: 2
Chandler Johnston
Chandler Johnston 2022년 11월 20일
Cool, I'll look into some of these options, I think the majority of these solutions will not work in my application, but I will look into the exchange contribution you shared and some of the TCP related options.
Thank you!
Walter Roberson
Walter Roberson 2022년 11월 20일
Or you could use ble for Bluetooth Low Energy

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interface-Based Communication에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by