Dobot mg400 stuck on tcpstart


#1

I am writing a code, so when the robot starts in creates a tcp socket and and it gets stuck on that code line, it is meant to create it, and then move on to listen it for incoming data from pc, Vision builder AI (NI soft).

THE CODE:
resultCreate1,socket1 = TCPCreate(true, ‘192.168.5.10’, 6601)
if resultCreate1 == 0 then
print(“Create TCP Server Success!”)
else
print(“Create TCP Server failed, code:”, resultCreate1)
end
TCPStart(socket1, 0)
–print(‘created’)
–Sync()
–print((resultCreate1))
Sleep(10)
Sync()
while 1 do
DO(16,1)
Wait(500)
DO(16,0)
resultRead1,x = TCPRead(socket1, 0,‘string’)
x = x.buf
x = tonumber(x)
Sleep(10)
Sync()
print(‘x:’)
Sync()
print(x)
resultRead1,y = TCPRead(socket1, 0,‘string’)
y = y.buf
y = tonumber(y)
Sleep(10)
Sync()
print(‘y:’)
Sync()
print(y)
Sleep(500)
MovJ(({coordinate = {x,y,0,0}, tool = 0, user = 0}))
DO(9,1)
Sleep(1000)
RelMovL({0,0,-92,0})
DO(9,0)
DO(10,1)
Sleep(3000)
RelMovL({0,0,92,0})
MovJ(({coordinate = {300,-150,0,0}, tool = 0, user = 0}))
DO(10,0)
Sleep(2000)
end


#2

So you want the robot to be the server?

I do it the other way around with this code:

::create_server::
	err, socket = TCPCreate(false, ip, port)
	if err ~= 0 then
		print("Failed to create socket, re-connecting")
		Sleep(1000)
		goto create_server
	end
    print("TCP socket created")
	err = TCPStart(socket, 0)
	if err ~= 0 then
		print("Failed to connect server, re-connecting")
		TCPDestroy(socket)
		Sleep(1000)
		goto create_server
	end
    print("TCP connection established")
    local RxBuffer
	print("Sending flash request to PC!")
	TCPWrite(socket,"Start!\n")
	print("Waiting for Start ack....")
	::receieve_ack::
	err, RxBuffer = TCPRead(socket,0,"string")
	--print("Rx ack data:",RxBuffer)
	if(RxBuffer.buf == "Ack!\n") then
	  print("Waiting for results....")
	  ::receive_data::
	  err, RxBuffer = TCPRead(socket,0,"string")
	  --print("Receive data:",RxBuffer)

	  if(RxBuffer.size < 6) then
		goto receive_data
	  end

The PC is running the server and waits for an incoming connection, the robot sends a start command to the pc, waits for ack and then waits for the result. (6bytes)

I hope this could be helpful for you or somebody else in some way.

I found this example in “Dobotstudio Pro User guide”
Example 1:
local ip=“192.168.5.1” // Set the IP address of the robot as the server
local port=6001 // Server port
local err=0
local socket=0
err, socket = TCPCreate(true, ip, port)

Try that and see, could it be the " " around the IP that makes the difference? (I’m no LUA expert)