Jump to content




Peripherals


  • You cannot reply to this topic
14 replies to this topic

#1 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 04:04 PM

Hello programmers,

i can a little bit lua but not enough for this :D

i have bounded 2 disk drives with an cable modem,

the problem is, how can i read them for the disk.isPresent command over rednet ?

i try to learn and understand rednet but not so easy for me :D

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 April 2015 - 04:09 PM

When you right-clicked to activate the modems attached to the disk drives, it generated a chat message saying something like "drive_0 connected to the network". Use that network name as the peripheral side name. Since the disk API functions can use a side name directly, it might look like this:

if disk.isPresent("drive_0") then
  --# do stuff
end


#3 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 04:12 PM

ah ok and have i to use the rednet.open() on at the programm ?

the hardware connecten had to be on but what is with the software ?

#4 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 05 April 2015 - 04:21 PM

Nope, you dont use rednet.

You simply do this:
local file = fs.open("disk","r")
where disk can also be disk2 depending on the number of the disk.


#5 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 04:24 PM

ok thanks i try it now,

when it not works i post it here ;)

thanks for the first part

#6 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 04:51 PM

ok now i have a problem i get an syntax error at line 23 and line 22 the same
term.clear()

drive1 = ("drive_0")-- Disk Drive 1
drive2 = ("drive_1")-- Disk Drive 2
disklabel = ("Securitycard")-- Disk Label Needed
Securitylp = ("Level 1 File")-- Security Level File Needed on Keycard





while true do

if (disk.isPresent(drive1) or (drive2)) then-- check if keycard in drive 1 or drive 2
   current_disklabel = disk.getLabel("disk") or ("disk2")-- get disklabel from disk
   if (current_disklabel == disklabel) then-- if disklabel = Needed disk Label
	 local file = fs.open("disk", "r")-- search for Security File
	 if file == Securitylp then-- when security file exist then give redstone signal
		redstone.setOutput("bottom", true)
		disk.eject("disk") --put Keycard out
		sleep(10) --wait 10 seconds and set redstone signal 0
		redstone.setOutput("bottom", false)
	 else (print("false"))-- restart computer or repeat the loop
   else (print("false"))-- restart computer or repeat the loop
end
end	  

so there where is print("false") i wnat to repeat the loop but i dont now how ?
the next think is i hope it works :D
very long time not written any programs in lua or other languages.

Edited by darcline, 05 April 2015 - 04:53 PM.


#7 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 05 April 2015 - 05:00 PM

term.clear() --OK

drive1 = ("drive_0")-- Disk Drive 1 -- string are declared like this stringname = "blahblah"
drive2 = ("drive_1")-- Disk Drive 2
disklabel = ("Securitycard")-- Disk Label Needed
Securitylp = ("Level 1 File")-- Security Level File Needed on Keycard





while true do

if (disk.isPresent(drive1) or (drive2)) then-- check if keycard in drive 1 or drive 2 -- make it ("drive") or ("drive2") drive1 is only disk
current_disklabel = disk.getLabel("disk") or ("disk2")-- get disklabel from disk --disk.getLabel("disk") or disk.getLabel("disk2")
if (current_disklabel == disklabel) then-- if disklabel = Needed disk Label --
local file = fs.open("disk", "r")-- search for Security File --s.open("diskWhaeverNumber/file", "r") use disk is present to see which disk is present
if file == Securitylp then-- when security file exist then give redstone signal -- you may mean if file.readAll() == Securitylp
redstone.setOutput("bottom", true) -- file.close()
disk.eject("disk") --put Keycard out -- check which disk
sleep(10) --wait 10 seconds and set redstone signal 0
redstone.setOutput("bottom", false)
else (print("false"))-- restart computer or repeat the loop
else (print("false"))-- restart computer or repeat the loop
end
end

Hope I helped you

#8 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 05:13 PM

ahm ok moment :D too much comments

it can only be one keycard at a time, why should i check which disk it put out ?

thanks for the file close i have forget it,

but the syntax error ist still allive

#9 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 06:45 PM

ok syntax error is gone but the programm is not working :/

it starts and goes directly to the start screen but why ?

anyone ideas ?

#10 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 05 April 2015 - 08:50 PM

term.clear()

drive1 = "disk_0"-- Disk Drive 1
drive2 = "disk_1"-- Disk Drive 2
disklabel = "Securitycard" -- Disk Label Needed
Securitylp = "Level 1 File" -- Security Level File Needed on Keycard
currentDisk = ""





while true do

if (disk.isPresent(drive1) or disk.isPresent(drive2)) then-- check if keycard in drive 1 or drive 2
  currentDisk = disk.isPresent(drive1) and "disk_1" or "disk_2"
   current_disklabel = disk.getLabel(currentDisk)-- get disklabel from disk
   if (current_disklabel == disklabel) then-- if disklabel = Needed disk Label
	 local file = fs.open(currentDisk.."/file", "r")-- search for Security File
	 if file.readAll() == Securitylp then-- when security file exist then give redstone signal
		redstone.setOutput("bottom", true)
		disk.eject("disk") --put Keycard out
		sleep(10) --wait 10 seconds and set redstone signal 0
		redstone.setOutput("bottom", false)
	 else (print("false"))-- restart computer or repeat the loop
   else (print("false"))-- restart computer or repeat the loop
end
end	  

Here is the the a little more lua standard following code ;)

#11 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 10:29 PM

oh thanks for your work but i write it complete new :D but your work was not totally (have no word sorry)

but i have a little problem i work with 2 monitors but the text is on 1 monitor only but i dont understand why :/

heres a code and 2 screens

term.clear()			   --terminal clearen
local mon1 = peripheral.wrap("monitor_3")
local mon2 = peripheral.wrap("monitor_2")
pstop = ("left")		   --programm stop
disk1 = ("drive_0")	    --Laufwerk 1
disk2 = ("drive_1")	    --Laufwerk 2
door = ("bottom")		  --Tuer Ausgang
code = ("Securitycard")    --KartenLabel
scode = ("/disk/Level_1_File")   --Sicherheitsstufe 1

while not redstone.getInput(pstop) do
	 if disk.isPresent(disk1) == true then
	    mon1.clear()
	    if disk.getLabel(disk1) == code then
		   if fs.exists(scode) == true then
			  disk.eject(disk1)
			  redstone.setOutput("bottom", true)
			  sleep(10)
			  redstone.setOutput("bottom", false)
			  shell.run("reboot")
		   else
			    mon1.write("Nicht Authorisiert")
			    sleep(5)
			    shell.run("reboot")
		   end
	    else    mon1.write("Fehlerhafte Sicherheitskarte")
			    sleep(5)
			    shell.run("reboot")
	    end
	 else
		  mon1.write("Keycard Einstecken")
	 end
	 if disk.isPresent(disk2) == true then
		    mon2.clear()
		    if disk.getLabel(disk2) == code then
		    print(file_exist2)
			   if fs.exists(scode) == true then
				  disk.eject(disk2)
				  redstone.setOutput("bottom", true)
				  sleep(10)
				  redstone.setOutput("bottom", false)
				  shell.run("reboot")
			   else
				    mon2.write("Nicht Authorisiert")
				    sleep(5)
				    shell.run("reboot")
			   end	  
			 else
				   mon2.write("Fehlerhafte Sicherheitskarte")
				    sleep(5)
				    shell.run("reboot")
			 end
		  else
			   mon2.write("Keycard Einstecken")
		  end
	  sleep(0.5)
end			  

sorry i cant upload the screens have problem with vdsl

#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 April 2015 - 10:37 PM

Looks to be because you're rebooting the computer all the time - well before you get to the second half of your script, where you check what's in the second disk drive.

#13 darcline

  • Members
  • 33 posts

Posted 05 April 2015 - 11:35 PM

Look again ;)

Its an or function the First drive or the second drive Not the drives at Same time
But the text keycard einstecken(insert keycard) should on 2 Monitors at Same time in didnt clear the monitor

#14 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 April 2015 - 11:56 PM

while no redstone signal do
	if there's a disk in the first drive then
		if it's labeled as a keycard then
			if the first mounted disk has a "Level_1_File" on it then
				reboot!
			else
				reboot!
			end
		else
			reboot!
		end
	else
		Don't reboot!
	end
	
	-- Program can only reach this point if the computer hasn't rebooted already!
	
	if there's a disk in the second drive then
		mon2.clear()
		if it's labeled as a keycard then
			print(file_exist2)
			if the first mounted disk (again) has a "Level_1_File" on it then
				reboot!
			else
				reboot!
			end    
		else
			reboot!
		end
	else
		Don't reboot!
	end
end


#15 darcline

  • Members
  • 33 posts

Posted 06 April 2015 - 12:21 AM

Jep if a Disk in the First drive if Not it ask if a Disk in the second drive, if Not wait 0,5 seconds and ask again
The last Reboot you mean is for the card label

while no redstone signal do
	    if there's a disk in the first drive then
			    if it's labeled as a keycard then
					    if the first mounted disk has a "Level_1_File" on it then
							    reboot!
					    else
							    reboot!
					    end
			    else
					    reboot!
			    end
	    else
			    Don't reboot!
	    end
	   
	    -- Program can only reach this point if the computer hasn't rebooted already!
	   
	    if there's a disk in the second drive then
			    mon2.clear()
			    if it's labeled as a keycard then
					    print(file_exist2)
					    if the first mounted disk (again) has a "Level_1_File" on it then
							    reboot! Reboot Yep
					    else
							    reboot! Reboot YEP
					    end   
			    else
					    reboot! Reboot Yep
			    end
	    else
			    Don't reboot!  Here is no Reboot
	    end
end

Edited by darcline, 06 April 2015 - 02:23 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users