Spaces:
Running
Running
can you create plc logic ?
Browse files- README.md +8 -5
- index.html +313 -18
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: Ladder Logic Luminary
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Ladder Logic Luminary 🚦
|
| 3 |
+
colorFrom: yellow
|
| 4 |
+
colorTo: red
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
index.html
CHANGED
|
@@ -1,19 +1,314 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>PLC Logic Simulator</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.ladder-rung {
|
| 12 |
+
height: 80px;
|
| 13 |
+
border-left: 4px solid #4B5563;
|
| 14 |
+
border-right: 4px solid #4B5563;
|
| 15 |
+
position: relative;
|
| 16 |
+
}
|
| 17 |
+
.ladder-rail {
|
| 18 |
+
width: 100%;
|
| 19 |
+
height: 4px;
|
| 20 |
+
background-color: #4B5563;
|
| 21 |
+
}
|
| 22 |
+
.contact {
|
| 23 |
+
width: 40px;
|
| 24 |
+
height: 40px;
|
| 25 |
+
border-radius: 50%;
|
| 26 |
+
display: flex;
|
| 27 |
+
align-items: center;
|
| 28 |
+
justify-content: center;
|
| 29 |
+
cursor: pointer;
|
| 30 |
+
transition: all 0.3s ease;
|
| 31 |
+
}
|
| 32 |
+
.contact.active {
|
| 33 |
+
background-color: #10B981;
|
| 34 |
+
}
|
| 35 |
+
.contact.inactive {
|
| 36 |
+
background-color: #EF4444;
|
| 37 |
+
}
|
| 38 |
+
.coil {
|
| 39 |
+
width: 50px;
|
| 40 |
+
height: 30px;
|
| 41 |
+
border-radius: 4px;
|
| 42 |
+
display: flex;
|
| 43 |
+
align-items: center;
|
| 44 |
+
justify-content: center;
|
| 45 |
+
cursor: pointer;
|
| 46 |
+
transition: all 0.3s ease;
|
| 47 |
+
}
|
| 48 |
+
.coil.active {
|
| 49 |
+
background-color: #10B981;
|
| 50 |
+
}
|
| 51 |
+
.coil.inactive {
|
| 52 |
+
background-color: #EF4444;
|
| 53 |
+
}
|
| 54 |
+
.wire {
|
| 55 |
+
height: 4px;
|
| 56 |
+
background-color: #4B5563;
|
| 57 |
+
}
|
| 58 |
+
.logic-gate {
|
| 59 |
+
width: 60px;
|
| 60 |
+
height: 60px;
|
| 61 |
+
display: flex;
|
| 62 |
+
align-items: center;
|
| 63 |
+
justify-content: center;
|
| 64 |
+
border-radius: 8px;
|
| 65 |
+
cursor: pointer;
|
| 66 |
+
transition: all 0.3s ease;
|
| 67 |
+
}
|
| 68 |
+
.logic-gate.active {
|
| 69 |
+
background-color: #10B981;
|
| 70 |
+
}
|
| 71 |
+
.logic-gate.inactive {
|
| 72 |
+
background-color: #EF4444;
|
| 73 |
+
}
|
| 74 |
+
</style>
|
| 75 |
+
</head>
|
| 76 |
+
<body class="bg-gray-100 min-h-screen">
|
| 77 |
+
<div class="container mx-auto px-4 py-8">
|
| 78 |
+
<header class="mb-8 text-center">
|
| 79 |
+
<h1 class="text-4xl font-bold text-gray-800 mb-2">PLC Logic Simulator</h1>
|
| 80 |
+
<p class="text-gray-600">Drag, drop, and simulate industrial control logic</p>
|
| 81 |
+
</header>
|
| 82 |
+
|
| 83 |
+
<div class="grid grid-cols-1 lg:grid-cols-4 gap-6">
|
| 84 |
+
<!-- Toolbox -->
|
| 85 |
+
<div class="bg-white rounded-lg shadow-md p-4 lg:col-span-1">
|
| 86 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-800">Components</h2>
|
| 87 |
+
<div class="space-y-3">
|
| 88 |
+
<div class="bg-gray-100 p-3 rounded-lg flex items-center cursor-move" draggable="true" data-type="contact-normally-open">
|
| 89 |
+
<i data-feather="circle" class="text-gray-700 mr-2"></i>
|
| 90 |
+
<span>NO Contact</span>
|
| 91 |
+
</div>
|
| 92 |
+
<div class="bg-gray-100 p-3 rounded-lg flex items-center cursor-move" draggable="true" data-type="contact-normally-closed">
|
| 93 |
+
<i data-feather="x" class="text-gray-700 mr-2"></i>
|
| 94 |
+
<span>NC Contact</span>
|
| 95 |
+
</div>
|
| 96 |
+
<div class="bg-gray-100 p-3 rounded-lg flex items-center cursor-move" draggable="true" data-type="coil">
|
| 97 |
+
<i data-feather="square" class="text-gray-700 mr-2"></i>
|
| 98 |
+
<span>Coil</span>
|
| 99 |
+
</div>
|
| 100 |
+
<div class="bg-gray-100 p-3 rounded-lg flex items-center cursor-move" draggable="true" data-type="timer">
|
| 101 |
+
<i data-feather="clock" class="text-gray-700 mr-2"></i>
|
| 102 |
+
<span>Timer</span>
|
| 103 |
+
</div>
|
| 104 |
+
<div class="bg-gray-100 p-3 rounded-lg flex items-center cursor-move" draggable="true" data-type="counter">
|
| 105 |
+
<i data-feather="hash" class="text-gray-700 mr-2"></i>
|
| 106 |
+
<span>Counter</span>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<!-- Workspace -->
|
| 112 |
+
<div class="bg-white rounded-lg shadow-md p-4 lg:col-span-3" id="workspace">
|
| 113 |
+
<div class="flex justify-between items-center mb-4">
|
| 114 |
+
<h2 class="text-xl font-semibold text-gray-800">Ladder Diagram</h2>
|
| 115 |
+
<div class="flex space-x-2">
|
| 116 |
+
<button class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center">
|
| 117 |
+
<i data-feather="play" class="mr-2"></i>
|
| 118 |
+
Run
|
| 119 |
+
</button>
|
| 120 |
+
<button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center">
|
| 121 |
+
<i data-feather="save" class="mr-2"></i>
|
| 122 |
+
Save
|
| 123 |
+
</button>
|
| 124 |
+
<button class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg flex items-center">
|
| 125 |
+
<i data-feather="trash-2" class="mr-2"></i>
|
| 126 |
+
Clear
|
| 127 |
+
</button>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
|
| 131 |
+
<div class="border-2 border-gray-300 rounded-lg p-6 min-h-[500px]" id="ladder-diagram">
|
| 132 |
+
<!-- Vertical rails -->
|
| 133 |
+
<div class="flex justify-between mb-4">
|
| 134 |
+
<div class="w-12 h-full border-r-2 border-gray-400"></div>
|
| 135 |
+
<div class="w-12 h-full border-l-2 border-gray-400"></div>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
<!-- Rung 1 -->
|
| 139 |
+
<div class="relative mb-8">
|
| 140 |
+
<div class="ladder-rail"></div>
|
| 141 |
+
<div class="ladder-rung flex items-center justify-center px-12">
|
| 142 |
+
<div class="contact inactive" data-type="contact-normally-open" data-id="1"></div>
|
| 143 |
+
<div class="wire w-16"></div>
|
| 144 |
+
<div class="coil inactive" data-type="coil" data-id="1"></div>
|
| 145 |
+
</div>
|
| 146 |
+
<div class="ladder-rail"></div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
<!-- Rung 2 -->
|
| 150 |
+
<div class="relative mb-8">
|
| 151 |
+
<div class="ladder-rail"></div>
|
| 152 |
+
<div class="ladder-rung flex items-center justify-center px-12">
|
| 153 |
+
<div class="contact inactive" data-type="contact-normally-closed" data-id="2"></div>
|
| 154 |
+
<div class="wire w-16"></div>
|
| 155 |
+
<div class="contact inactive" data-type="contact-normally-open" data-id="3"></div>
|
| 156 |
+
<div class="wire w-16"></div>
|
| 157 |
+
<div class="coil inactive" data-type="coil" data-id="2"></div>
|
| 158 |
+
</div>
|
| 159 |
+
<div class="ladder-rail"></div>
|
| 160 |
+
</div>
|
| 161 |
+
|
| 162 |
+
<!-- Empty rung template (hidden) -->
|
| 163 |
+
<div class="hidden" id="rung-template">
|
| 164 |
+
<div class="relative mb-8">
|
| 165 |
+
<div class="ladder-rail"></div>
|
| 166 |
+
<div class="ladder-rung flex items-center justify-center px-12"></div>
|
| 167 |
+
<div class="ladder-rail"></div>
|
| 168 |
+
</div>
|
| 169 |
+
</div>
|
| 170 |
+
</div>
|
| 171 |
+
|
| 172 |
+
<div class="mt-4 flex justify-center">
|
| 173 |
+
<button id="add-rung" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-lg flex items-center">
|
| 174 |
+
<i data-feather="plus" class="mr-2"></i>
|
| 175 |
+
Add Rung
|
| 176 |
+
</button>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
</div>
|
| 180 |
+
|
| 181 |
+
<div class="mt-8 bg-white rounded-lg shadow-md p-4">
|
| 182 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-800">I/O Monitor</h2>
|
| 183 |
+
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
| 184 |
+
<div class="bg-gray-100 p-4 rounded-lg">
|
| 185 |
+
<div class="flex justify-between items-center">
|
| 186 |
+
<span>Input 1</span>
|
| 187 |
+
<div class="w-4 h-4 rounded-full bg-red-500 toggle-input" data-id="1"></div>
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
<div class="bg-gray-100 p-4 rounded-lg">
|
| 191 |
+
<div class="flex justify-between items-center">
|
| 192 |
+
<span>Input 2</span>
|
| 193 |
+
<div class="w-4 h-4 rounded-full bg-red-500 toggle-input" data-id="2"></div>
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
<div class="bg-gray-100 p-4 rounded-lg">
|
| 197 |
+
<div class="flex justify-between items-center">
|
| 198 |
+
<span>Output 1</span>
|
| 199 |
+
<div class="w-4 h-4 rounded-full bg-red-500" id="output-1"></div>
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
<div class="bg-gray-100 p-4 rounded-lg">
|
| 203 |
+
<div class="flex justify-between items-center">
|
| 204 |
+
<span>Output 2</span>
|
| 205 |
+
<div class="w-4 h-4 rounded-full bg-red-500" id="output-2"></div>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
</div>
|
| 211 |
+
|
| 212 |
+
<script>
|
| 213 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 214 |
+
feather.replace();
|
| 215 |
+
|
| 216 |
+
// Simple simulation logic
|
| 217 |
+
const toggleInputs = document.querySelectorAll('.toggle-input');
|
| 218 |
+
const contacts = document.querySelectorAll('[data-type^="contact"]');
|
| 219 |
+
const coils = document.querySelectorAll('[data-type="coil"]');
|
| 220 |
+
const outputs = [document.getElementById('output-1'), document.getElementById('output-2')];
|
| 221 |
+
|
| 222 |
+
toggleInputs.forEach(input => {
|
| 223 |
+
input.addEventListener('click', function() {
|
| 224 |
+
const isActive = this.classList.contains('bg-green-500');
|
| 225 |
+
this.classList.toggle('bg-green-500', !isActive);
|
| 226 |
+
this.classList.toggle('bg-red-500', isActive);
|
| 227 |
+
updateSimulation();
|
| 228 |
+
});
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
function updateSimulation() {
|
| 232 |
+
// Get input states
|
| 233 |
+
const input1 = toggleInputs[0].classList.contains('bg-green-500');
|
| 234 |
+
const input2 = toggleInputs[1].classList.contains('bg-green-500');
|
| 235 |
+
|
| 236 |
+
// Update contacts based on inputs
|
| 237 |
+
contacts.forEach(contact => {
|
| 238 |
+
const id = contact.dataset.id;
|
| 239 |
+
if (contact.dataset.type === 'contact-normally-open') {
|
| 240 |
+
if ((id === '1' && input1) || (id === '3' && input2)) {
|
| 241 |
+
contact.classList.add('active');
|
| 242 |
+
contact.classList.remove('inactive');
|
| 243 |
+
} else {
|
| 244 |
+
contact.classList.add('inactive');
|
| 245 |
+
contact.classList.remove('active');
|
| 246 |
+
}
|
| 247 |
+
} else if (contact.dataset.type === 'contact-normally-closed') {
|
| 248 |
+
if ((id === '2' && !input1)) {
|
| 249 |
+
contact.classList.add('active');
|
| 250 |
+
contact.classList.remove('inactive');
|
| 251 |
+
} else {
|
| 252 |
+
contact.classList.add('inactive');
|
| 253 |
+
contact.classList.remove('active');
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
});
|
| 257 |
+
|
| 258 |
+
// Calculate outputs
|
| 259 |
+
const output1 = document.querySelector('[data-id="1"].active') !== null;
|
| 260 |
+
const output2 = document.querySelector('[data-id="2"].active') !== null &&
|
| 261 |
+
document.querySelector('[data-id="3"].active') !== null;
|
| 262 |
+
|
| 263 |
+
// Update coils and outputs
|
| 264 |
+
coils.forEach(coil => {
|
| 265 |
+
const id = coil.dataset.id;
|
| 266 |
+
if ((id === '1' && output1) || (id === '2' && output2)) {
|
| 267 |
+
coil.classList.add('active');
|
| 268 |
+
coil.classList.remove('inactive');
|
| 269 |
+
} else {
|
| 270 |
+
coil.classList.add('inactive');
|
| 271 |
+
coil.classList.remove('active');
|
| 272 |
+
}
|
| 273 |
+
});
|
| 274 |
+
|
| 275 |
+
// Update output indicators
|
| 276 |
+
outputs[0].classList.toggle('bg-green-500', output1);
|
| 277 |
+
outputs[0].classList.toggle('bg-red-500', !output1);
|
| 278 |
+
outputs[1].classList.toggle('bg-green-500', output2);
|
| 279 |
+
outputs[1].classList.toggle('bg-red-500', !output2);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
// Add new rung
|
| 283 |
+
document.getElementById('add-rung').addEventListener('click', function() {
|
| 284 |
+
const template = document.getElementById('rung-template');
|
| 285 |
+
const newRung = template.cloneNode(true);
|
| 286 |
+
newRung.classList.remove('hidden');
|
| 287 |
+
document.getElementById('ladder-diagram').appendChild(newRung);
|
| 288 |
+
});
|
| 289 |
+
|
| 290 |
+
// Simple drag and drop (placeholder functionality)
|
| 291 |
+
const draggables = document.querySelectorAll('[draggable="true"]');
|
| 292 |
+
const workspace = document.getElementById('workspace');
|
| 293 |
+
|
| 294 |
+
draggables.forEach(draggable => {
|
| 295 |
+
draggable.addEventListener('dragstart', function(e) {
|
| 296 |
+
e.dataTransfer.setData('text/plain', this.dataset.type);
|
| 297 |
+
});
|
| 298 |
+
});
|
| 299 |
+
|
| 300 |
+
workspace.addEventListener('dragover', function(e) {
|
| 301 |
+
e.preventDefault();
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
workspace.addEventListener('drop', function(e) {
|
| 305 |
+
e.preventDefault();
|
| 306 |
+
const type = e.dataTransfer.getData('text/plain');
|
| 307 |
+
// In a real implementation, you would create a new component at the drop position
|
| 308 |
+
alert(`Dropped ${type} component. In a full implementation, this would create a new ${type} on the ladder diagram.`);
|
| 309 |
+
});
|
| 310 |
+
});
|
| 311 |
+
</script>
|
| 312 |
+
<script>feather.replace();</script>
|
| 313 |
+
</body>
|
| 314 |
</html>
|