Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: djmickyg on June 05, 2020, 06:29:27 AM

Title: M code to capture image from USB camera
Post by: djmickyg 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


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") 




https://batchloaf.wordpress.com/commandcam/ (https://batchloaf.wordpress.com/commandcam/)
Title: Re: M code to capture image from USB camera
Post by: TPS 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
Title: Re: M code to capture image from USB camera
Post by: djmickyg on June 07, 2020, 10:34:15 AM
Thanks! I'll give these a shot