Shell equivalent of matlab fwrite function


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell equivalent of matlab fwrite function
# 1  
Old 10-27-2015
Shell equivalent of matlab fwrite function

I have some matlab code that sends the serial port elements of an array using matlab's fwrite function, e.g.:
Code:
fwrite(s, [170 01 06 06 85], 'uchar');

What would be a unix shell equivalent? E.g., after successfully accessing the port using instructions here:

Simple terminal serial port program for Linux/MacOSX in C

this doesn't work to write to the port:
Code:
echo -e '107 01 06 06 85' > /dev/tty.PL2303-0000101D

Moderator's Comments:
Mod Comment edit by bakunin: corrected link description

Last edited by bakunin; 10-28-2015 at 12:21 PM..
# 2  
Old 10-27-2015
Are you attempting to write raw, binary characters to the serial port? You were writing the literal characters 1, 0, 7, ' ', 0, etc.

Code:
# Set serial port in raw mode, so binary passes unmangled
stty raw -F /dev/ttywhatever
# Convert decimal numbers into \xYY hexadecimal escape sequences
HEX="$(printf '\\x%02x' 107 01 06 06 85)"
# Convert escape sequences into raw binary, write to serial port
printf "$HEX" > /dev/ttywhatever

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 10-29-2015
Perfect - thanks!
# 4  
Old 11-13-2015
Sorry - one other question. Although I can send the codes to port, it is very slow. I'm not sure why. I tried changing the baud rate but that didn't make any difference.

Not sure if this is relevant, but with the matlab serial function, I have the 'OutputBufferSize' argument set to 65535. Is there some equivalent argument for stty?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Equivalent to let command in POSIX shell

Hi all, I am learning POSIX shell programming, and the book I read, uses the let command for integer arithmetic. I have downloaded and use the shellcheck program on Linux. This programs says: In POSIX sh, 'let' is undefined. See the screenshot attached. What is the POSIX... (1 Reply)
Discussion started by: johnprogrammer
1 Replies

2. Shell Programming and Scripting

Java - Arrays.binarySearch function equivalent in awk

Hi all Does anyone know Java-Arrays.binarySearch function equivalent in awk I tried like this but it's not correct one,it just returns array index if and only when searched value available in array, for some reason if searched value not found then I want to return upper nearest neighbour index.... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

3. Programming

The fwrite function is not returning error, if the file was removed.

The fwrite function call is not returning error, when the file it writes to is removed, please advise on how to find if the file already opened and being written by a program is removed manually or by some other process. please see the code below, #include<stdio.h> #include<stdlib.h> ... (3 Replies)
Discussion started by: Kesavan
3 Replies

4. Shell Programming and Scripting

Output of matlab as a variable for shell script

I'm running a matlab code within a shell script. This is how I do it, matlab -nodesktop -nosplash -nojvm -r "my_program;quit" This works fine. My matlab code prints out a single number, say "ans = 10" for example. I want to assign this to a variable in the shell script. I tried doing this... (18 Replies)
Discussion started by: lost.identity
18 Replies

5. Programming

Equivalent function for matlab on scilab

Hello everyone, i need help with this , i need the equivalent matlab funtion tf(x,y) in scilab and what do u recommend best from those three for a linux user (i need it for Control theory): 1-matlab 2-Scilab 3-Octave thank you for your time (0 Replies)
Discussion started by: abu_malek
0 Replies

6. Programming

segmentation fault in fwrite function

Hi, my code is written in proC and it is in UNIX(AIX).I have written a small code for writing data into a binary file,but while writing my program is giving core dump. Here Is my code---- fpWriteFile = fopen(WriteFileName,"wb+"); CHAR *recvgen; recvgen = (char... (7 Replies)
Discussion started by: ajaysahoo
7 Replies

7. Shell Programming and Scripting

shell script equivalent for tcl function

Hello, I need experts help in converting the below tcl function to korn shell function equivalent. proc lsNetMaskToBits {mask} { set dw ; # Top N bits set set dw 0x ; # Make sure it's hexadecimal, else XOR fails. puts "lsNetMaskToBits dw $dw" set dw ; # Complement => low 32-N bits... (1 Reply)
Discussion started by: JackMelson
1 Replies

8. Shell Programming and Scripting

Bash equivalent of perl's pack function ?

Is there an equivalent of perl's pack function in bash ? Or in other words, how can I achieve the same thing in bash ? Much appreciated. (1 Reply)
Discussion started by: NewDeb
1 Replies

9. Programming

equivalent function for wherey( ) ??

what is the equivalent function for wherey( ) ?? That is to return the current column position? (2 Replies)
Discussion started by: rockgal
2 Replies

10. Linux

Equivalent function of [ kbhit() ] In TURBO C

ANy one knows equivalent function of which in Turbo C. I want to Execute Certain loop until any key is pressed. i.e while(!kbhit) { ---------- ---------- } This code work fine in DOS but NOt in LINUX i try to use but not getting the expected result ... (0 Replies)
Discussion started by: niravuchat
0 Replies
Login or Register to Ask a Question