Hello Guest it is January 27, 2022, 06:20:50 PM

Author Topic: M code to capture image from USB camera  (Read 827 times)

0 Members and 1 Guest are viewing this topic.

M code to capture image from USB camera
« on: June 05, 2020, 06:29:27 AM »
I want to be able to capture images from the USB microscope. I will be moving the axes by small increments and taking a bunch of photos which i will later stitch together.
I havent been able to find a plug in that does this. I've come up with something of my own using CommandCam, my script is creating a .bat file which is creating a unique name for each image based on date_time_xyz pos, i am then running the bat files.

it's working, sort of, but i have a few issues.
I've set it to M2000

  • first issue is the script isn't waiting for the bat file to finish executing, i saw somewhere in the vb script manual about a wait but i can't remember where it was
  • second issue, when i load the gcode into MAch3 with the M2000 command, MACH3 obviously runs through the code to check for errors, when it runs through any gcode with M2000 it will run the bat files. if there a way I can get the script to only run when cycle start and not when checking for errors on load??

here is a code, this is in a file called M2000.m1s

Code: [Select]
Rem VBScript To capture image To file from camera

Rem date = Date()
x_current = "x" + CStr(GetUserDRO(0))
y_current = "y" + CStr(GetUserDRO(1))
z_current = "z" + CStr(GetUserDRO(2))
date_now = Date()
time_now = Time(Now)
date_string = CStr(Year(date_now)) + CStr(Month(date_now)) + CStr(Day(date_now))
time_string = CStr(Hour(time_now )) + "-" + CStr(Minute(time_now )) + "-" + CStr(Second(time_now ))

output_dir = "c:\cnc_cam\"
file_name =  x_current + "_" + y_current + "_" + z_current + ".bmp"

output_file = "CommandCam.bat"

Open output_file For Output As #1
Print #1, "cd " + output_dir
Print #1, "CommandCam /quiet /delay 100 /filename " + date_string + "_" + time_string + "_" + file_name
Close #1

Shell ( "CommandCam.bat") 


Offline TPS

  •  2,218 2,218
    • View Profile
Re: M code to capture image from USB camera
« Reply #1 on: June 06, 2020, 02:29:18 AM »
for 1. you can try to add a Sleep(1234), time is in milliseconds, to wait for the camera is finished

for 2. Config -> General config -> General Configuration -> Ignore M calls while loading
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: M code to capture image from USB camera
« Reply #2 on: June 07, 2020, 10:34:15 AM »
Thanks! I'll give these a shot